Skip to content

Commit

Permalink
sysroot: Use glnx_fstatat_allow_noent, drop ot_path_exists
Browse files Browse the repository at this point in the history
  • Loading branch information
ruihe774 committed Dec 20, 2024
1 parent 627b4f8 commit c7caee9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 31 deletions.
10 changes: 4 additions & 6 deletions src/libostree/ostree-sysroot.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,25 +474,23 @@ remount_writable (const char *path, gboolean *did_remount, GError **error)
static gboolean
_ostree_sysroot_invisible (const OstreeSysroot *self, gboolean *out_val, GError **error)
{
gboolean exists;

g_assert (self->sysroot_fd >= 0);
g_assert (self->root_is_ostree_booted);

if (!ot_path_exists (self->sysroot_fd, "sysroot/ostree", &exists, error))
if (!glnx_fstatat_allow_noent (self->sysroot_fd, "sysroot/ostree", NULL, 0, error))
return FALSE;

if (exists)
if (errno == 0)
{
*out_val = FALSE;
return TRUE;
}

// root_is_ostree_booted is true so we can use AT_FDCWD here
if (!ot_path_exists (AT_FDCWD, OTCORE_RUN_OSTREE_PRIVATE "/sysroot-ns", &exists, error))
if (!glnx_fstatat_allow_noent (AT_FDCWD, OTCORE_RUN_OSTREE_PRIVATE "/sysroot-ns", NULL, 0, error))
return FALSE;

if (!exists)
if (errno != 0)
{
*out_val = FALSE;
return TRUE;
Expand Down
23 changes: 0 additions & 23 deletions src/libotutil/ot-fs-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,26 +277,3 @@ ot_get_dir_size (int dfd, const char *path, guint64 blocksize, guint64 *out_size

return TRUE;
}

/* Check whether a path exists */
gboolean
ot_path_exists (int dfd, const char *path, gboolean *out_val, GError **error)
{
g_autoptr (GError) local_error = NULL;

struct stat stbuf;
if (glnx_fstatat (dfd, path, &stbuf, 0, &local_error))
{
*out_val = TRUE;
return TRUE;
}

if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
{
*out_val = FALSE;
return TRUE;
}

g_propagate_error (error, local_error);
return FALSE;
}
2 changes: 0 additions & 2 deletions src/libotutil/ot-fs-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,4 @@ gboolean ot_parse_file_by_line (const char *path, gboolean (*cb) (const char *,
gboolean ot_get_dir_size (int dfd, const char *path, guint64 blocksize, guint64 *out_size,
GCancellable *cancellable, GError **error);

gboolean ot_path_exists (int dfd, const char *path, gboolean *out_val, GError **error);

G_END_DECLS

0 comments on commit c7caee9

Please sign in to comment.