Replace openat() calls from libgsystem

This commit is contained in:
Alexander Larsson
2016-08-22 14:12:31 +02:00
parent b8a5a0092c
commit fcffefee26
4 changed files with 50 additions and 13 deletions

View File

@@ -75,9 +75,8 @@ export_dir (int source_parent_fd,
}
}
if (!gs_file_open_dir_fd_at (destination_parent_fd, destination_name,
&destination_dfd,
cancellable, error))
if (!glnx_opendirat (destination_parent_fd, destination_name, TRUE,
&destination_dfd, error))
return FALSE;
while (TRUE)

View File

@@ -2153,7 +2153,7 @@ export_desktop_file (const char *app,
g_autofree char *escaped_arch = maybe_quote (arch);
int i;
if (!gs_file_openat_noatime (parent_fd, name, &desktop_fd, cancellable, error))
if (!flatpak_openat_noatime (parent_fd, name, &desktop_fd, cancellable, error))
goto out;
if (!read_fd (desktop_fd, stat_buf, &data, &data_len, error))
@@ -2418,9 +2418,8 @@ export_dir (int source_parent_fd,
}
}
if (!gs_file_open_dir_fd_at (destination_parent_fd, destination_name,
&destination_dfd,
cancellable, error))
if (!glnx_opendirat (destination_parent_fd, destination_name, TRUE,
&destination_dfd, error))
goto out;
while (TRUE)

View File

@@ -754,9 +754,8 @@ overlay_symlink_tree_dir (int source_parent_fd,
}
}
if (!gs_file_open_dir_fd_at (destination_parent_fd, destination_name,
&destination_dfd,
cancellable, error))
if (!glnx_opendirat (destination_parent_fd, destination_name, TRUE,
&destination_dfd, error))
goto out;
while (TRUE)
@@ -1422,6 +1421,41 @@ flatpak_file_get_path_cached (GFile *file)
return path;
}
gboolean
flatpak_openat_noatime (int dfd,
const char *name,
int *ret_fd,
GCancellable *cancellable,
GError **error)
{
int fd;
int flags = O_RDONLY | O_CLOEXEC;
#ifdef O_NOATIME
do
fd = openat (dfd, name, flags | O_NOATIME, 0);
while (G_UNLIKELY (fd == -1 && errno == EINTR));
/* Only the owner or superuser may use O_NOATIME; so we may get
* EPERM. EINVAL may happen if the kernel is really old...
*/
if (fd == -1 && (errno == EPERM || errno == EINVAL))
#endif
do
fd = openat (dfd, name, flags, 0);
while (G_UNLIKELY (fd == -1 && errno == EINTR));
if (fd == -1)
{
glnx_set_error_from_errno (error);
return FALSE;
}
else
{
*ret_fd = fd;
return TRUE;
}
}
gboolean
flatpak_cp_a (GFile *src,
GFile *dest,
@@ -1462,11 +1496,10 @@ flatpak_cp_a (GFile *src,
goto out;
}
if (!gs_file_open_dir_fd (dest, &dest_dfd,
cancellable, error))
if (!glnx_opendirat (AT_FDCWD, flatpak_file_get_path_cached (dest), TRUE,
&dest_dfd, error))
goto out;
if (!no_chown)
{
do

View File

@@ -258,6 +258,12 @@ gboolean flatpak_spawnv (GFile *dir,
const char *flatpak_file_get_path_cached (GFile *file);
gboolean flatpak_openat_noatime (int dfd,
const char *name,
int *ret_fd,
GCancellable *cancellable,
GError **error);
typedef enum {
FLATPAK_CP_FLAGS_NONE = 0,
FLATPAK_CP_FLAGS_MERGE = 1<<0,