mirror of
https://github.com/ostreedev/ostree.git
synced 2024-12-23 21:35:26 +03:00
tree-wide: Some glnx_fstatat_allow_noent() porting
The new API is definitely nicer. Closes: #1180 Approved by: jlebon
This commit is contained in:
parent
c62b36046b
commit
13c3898cc2
@ -1249,12 +1249,10 @@ cleanup_tmpdir (OstreeRepo *self,
|
||||
if (strcmp (dent->d_name, "cache") == 0)
|
||||
continue;
|
||||
|
||||
if (TEMP_FAILURE_RETRY (fstatat (dfd_iter.fd, dent->d_name, &stbuf, AT_SYMLINK_NOFOLLOW)) < 0)
|
||||
{
|
||||
if (!glnx_fstatat_allow_noent (dfd_iter.fd, dent->d_name, &stbuf, AT_SYMLINK_NOFOLLOW, error))
|
||||
return FALSE;
|
||||
if (errno == ENOENT) /* Did another cleanup win? */
|
||||
continue;
|
||||
return glnx_throw_errno_prefix (error, "fstatat(%s)", dent->d_name);
|
||||
}
|
||||
|
||||
/* First, if it's a directory which needs locking, but it's
|
||||
* busy, skip it.
|
||||
|
@ -545,12 +545,10 @@ _ostree_repo_list_refs_internal (OstreeRepo *self,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr(GHashTable) ret_all_refs = NULL;
|
||||
g_autofree char *remote = NULL;
|
||||
g_autofree char *ref_prefix = NULL;
|
||||
|
||||
ret_all_refs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
|
||||
|
||||
g_autoptr(GHashTable) ret_all_refs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
|
||||
if (refspec_prefix)
|
||||
{
|
||||
struct stat stbuf;
|
||||
@ -571,12 +569,9 @@ _ostree_repo_list_refs_internal (OstreeRepo *self,
|
||||
path = glnx_strjoina (prefix_path, ref_prefix);
|
||||
}
|
||||
|
||||
if (fstatat (self->repo_dir_fd, path, &stbuf, 0) < 0)
|
||||
{
|
||||
if (errno != ENOENT)
|
||||
return glnx_throw_errno (error);
|
||||
}
|
||||
else
|
||||
if (!glnx_fstatat_allow_noent (self->repo_dir_fd, path, &stbuf, 0, error))
|
||||
return FALSE;
|
||||
if (errno == 0)
|
||||
{
|
||||
if (S_ISDIR (stbuf.st_mode))
|
||||
{
|
||||
|
@ -1806,7 +1806,9 @@ repo_create_at_internal (int dfd,
|
||||
/* Early return if we have an existing repo */
|
||||
{ g_autofree char *objects_path = g_build_filename (path, "objects", NULL);
|
||||
|
||||
if (fstatat (dfd, objects_path, &stbuf, 0) == 0)
|
||||
if (!glnx_fstatat_allow_noent (dfd, objects_path, &stbuf, 0, error))
|
||||
return FALSE;
|
||||
if (errno == 0)
|
||||
{
|
||||
glnx_fd_close int repo_dfd = -1;
|
||||
if (!glnx_opendirat (dfd, path, TRUE, &repo_dfd, error))
|
||||
@ -1816,8 +1818,6 @@ repo_create_at_internal (int dfd,
|
||||
*out_dfd = glnx_steal_fd (&repo_dfd);
|
||||
return TRUE;
|
||||
}
|
||||
else if (errno != ENOENT)
|
||||
return glnx_throw_errno_prefix (error, "fstatat");
|
||||
}
|
||||
|
||||
if (mkdirat (dfd, path, 0755) != 0)
|
||||
@ -1830,8 +1830,8 @@ repo_create_at_internal (int dfd,
|
||||
if (!glnx_opendirat (dfd, path, TRUE, &repo_dfd, error))
|
||||
return FALSE;
|
||||
|
||||
if (fstatat (repo_dfd, "config", &stbuf, 0) < 0)
|
||||
{
|
||||
if (!glnx_fstatat_allow_noent (repo_dfd, "config", &stbuf, 0, error))
|
||||
return FALSE;
|
||||
if (errno == ENOENT)
|
||||
{
|
||||
const char *mode_str = NULL;
|
||||
@ -1854,9 +1854,6 @@ repo_create_at_internal (int dfd,
|
||||
0, cancellable, error))
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
return glnx_throw_errno_prefix (error, "fstatat");
|
||||
}
|
||||
|
||||
for (guint i = 0; i < G_N_ELEMENTS (state_dirs); i++)
|
||||
{
|
||||
|
@ -689,12 +689,10 @@ selinux_relabel_var_if_needed (OstreeSysroot *sysroot,
|
||||
* when doing a deployment.
|
||||
*/
|
||||
const char selabeled[] = "var/.ostree-selabeled";
|
||||
gboolean deployment_var_labeled;
|
||||
|
||||
if (!ot_query_exists_at (os_deploy_dfd, selabeled, &deployment_var_labeled, error))
|
||||
struct stat stbuf;
|
||||
if (!glnx_fstatat_allow_noent (os_deploy_dfd, selabeled, &stbuf, AT_SYMLINK_NOFOLLOW, error))
|
||||
return FALSE;
|
||||
|
||||
if (!deployment_var_labeled)
|
||||
if (errno == ENOENT)
|
||||
{
|
||||
{ g_autofree char *msg =
|
||||
g_strdup_printf ("Relabeling /var (no stamp file '%s' found)", selabeled);
|
||||
@ -764,12 +762,13 @@ merge_configuration (OstreeSysroot *sysroot,
|
||||
}
|
||||
}
|
||||
|
||||
gboolean etc_exists = FALSE;
|
||||
if (!ot_query_exists_at (deployment_dfd, "etc", &etc_exists, error))
|
||||
struct stat stbuf;
|
||||
if (!glnx_fstatat_allow_noent (deployment_dfd, "etc", &stbuf, AT_SYMLINK_NOFOLLOW, error))
|
||||
return FALSE;
|
||||
gboolean usretc_exists = FALSE;
|
||||
if (!ot_query_exists_at (deployment_dfd, "usr/etc", &usretc_exists, error))
|
||||
gboolean etc_exists = (errno == 0);
|
||||
if (!glnx_fstatat_allow_noent (deployment_dfd, "usr/etc", &stbuf, AT_SYMLINK_NOFOLLOW, error))
|
||||
return FALSE;
|
||||
gboolean usretc_exists = (errno == 0);
|
||||
|
||||
if (etc_exists && usretc_exists)
|
||||
return glnx_throw (error, "Tree contains both /etc and /usr/etc");
|
||||
@ -1568,10 +1567,10 @@ install_deployment_kernel (OstreeSysroot *sysroot,
|
||||
* it doesn't exist already.
|
||||
*/
|
||||
struct stat stbuf;
|
||||
if (fstatat (bootcsum_dfd, kernel_layout->kernel_namever, &stbuf, 0) != 0)
|
||||
if (!glnx_fstatat_allow_noent (bootcsum_dfd, kernel_layout->kernel_namever, &stbuf, 0, error))
|
||||
return FALSE;
|
||||
if (errno == ENOENT)
|
||||
{
|
||||
if (errno != ENOENT)
|
||||
return glnx_throw_errno_prefix (error, "fstat %s", kernel_layout->kernel_namever);
|
||||
if (!hardlink_or_copy_at (kernel_layout->boot_dfd,
|
||||
kernel_layout->kernel_srcpath,
|
||||
bootcsum_dfd, kernel_layout->kernel_namever,
|
||||
@ -1586,10 +1585,10 @@ install_deployment_kernel (OstreeSysroot *sysroot,
|
||||
if (kernel_layout->initramfs_srcpath)
|
||||
{
|
||||
g_assert (kernel_layout->initramfs_namever);
|
||||
if (fstatat (bootcsum_dfd, kernel_layout->initramfs_namever, &stbuf, 0) != 0)
|
||||
if (!glnx_fstatat_allow_noent (bootcsum_dfd, kernel_layout->initramfs_namever, &stbuf, 0, error))
|
||||
return FALSE;
|
||||
if (errno == ENOENT)
|
||||
{
|
||||
if (errno != ENOENT)
|
||||
return glnx_throw_errno_prefix (error, "fstat %s", kernel_layout->initramfs_namever);
|
||||
if (!hardlink_or_copy_at (kernel_layout->boot_dfd, kernel_layout->initramfs_srcpath,
|
||||
bootcsum_dfd, kernel_layout->initramfs_namever,
|
||||
sysroot->debug_flags,
|
||||
@ -1599,20 +1598,15 @@ install_deployment_kernel (OstreeSysroot *sysroot,
|
||||
}
|
||||
|
||||
g_autofree char *contents = NULL;
|
||||
if (fstatat (deployment_dfd, "usr/lib/os-release", &stbuf, 0) != 0)
|
||||
{
|
||||
if (errno != ENOENT)
|
||||
{
|
||||
return glnx_throw_errno (error);
|
||||
}
|
||||
else
|
||||
if (!glnx_fstatat_allow_noent (deployment_dfd, "usr/lib/os-release", &stbuf, 0, error))
|
||||
return FALSE;
|
||||
if (errno == ENOENT)
|
||||
{
|
||||
contents = glnx_file_get_contents_utf8_at (deployment_dfd, "etc/os-release", NULL,
|
||||
cancellable, error);
|
||||
if (!contents)
|
||||
return glnx_prefix_error (error, "Reading /etc/os-release");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
contents = glnx_file_get_contents_utf8_at (deployment_dfd, "usr/lib/os-release", NULL,
|
||||
|
@ -541,12 +541,9 @@ parse_origin (OstreeSysroot *self,
|
||||
g_autoptr(GKeyFile) ret_origin = g_key_file_new ();
|
||||
|
||||
struct stat stbuf;
|
||||
if (fstatat (deployment_dfd, origin_path, &stbuf, 0) != 0)
|
||||
{
|
||||
if (errno != ENOENT)
|
||||
return glnx_throw_errno (error);
|
||||
}
|
||||
else
|
||||
if (!glnx_fstatat_allow_noent (deployment_dfd, origin_path, &stbuf, 0, error))
|
||||
return FALSE;
|
||||
if (errno == 0)
|
||||
{
|
||||
g_autofree char *origin_contents =
|
||||
glnx_file_get_contents_utf8_at (deployment_dfd, origin_path,
|
||||
@ -808,8 +805,8 @@ ostree_sysroot_load_if_changed (OstreeSysroot *self,
|
||||
return FALSE;
|
||||
|
||||
struct stat stbuf;
|
||||
if (fstatat (self->sysroot_fd, "ostree/deploy", &stbuf, 0) < 0)
|
||||
return glnx_throw_errno_prefix (error, "fstatat");
|
||||
if (!glnx_fstatat (self->sysroot_fd, "ostree/deploy", &stbuf, 0, error))
|
||||
return FALSE;
|
||||
|
||||
if (out_changed)
|
||||
{
|
||||
|
@ -104,27 +104,6 @@ ot_ensure_unlinked_at (int dfd,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
ot_query_exists_at (int dfd, const char *path,
|
||||
gboolean *out_exists,
|
||||
GError **error)
|
||||
{
|
||||
struct stat stbuf;
|
||||
gboolean ret_exists;
|
||||
|
||||
if (fstatat (dfd, path, &stbuf, AT_SYMLINK_NOFOLLOW) < 0)
|
||||
{
|
||||
if (errno != ENOENT)
|
||||
return glnx_throw_errno_prefix (error, "fstatat(%s)", path);
|
||||
ret_exists = FALSE;
|
||||
}
|
||||
else
|
||||
ret_exists = TRUE;
|
||||
|
||||
*out_exists = ret_exists;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
ot_openat_ignore_enoent (int dfd,
|
||||
const char *path,
|
||||
|
@ -66,11 +66,6 @@ gboolean ot_openat_read_stream (int dfd,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
|
||||
gboolean ot_query_exists_at (int dfd, const char *path,
|
||||
gboolean *out_exists,
|
||||
GError **error);
|
||||
|
||||
gboolean ot_ensure_unlinked_at (int dfd,
|
||||
const char *path,
|
||||
GError **error);
|
||||
|
Loading…
Reference in New Issue
Block a user