summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Lebon <jonathan@jlebon.com>2023-04-13 17:22:37 -0400
committerJonathan Lebon <jonathan@jlebon.com>2023-04-14 09:55:38 -0400
commit91b6e5ded69ed03feb89ec7167007285dca9aa10 (patch)
treee28031e27e57d9992eeca481da4537908c53d689
parentc9271423b1c780ccb9ff47685d22d744968d9d19 (diff)
downloadostree-91b6e5ded69ed03feb89ec7167007285dca9aa10.tar.gz
lib/sysroot-cleanup: Convert bootdir listing to dfd-relative
No functional change.
-rw-r--r--src/libostree/ostree-sysroot-cleanup.c79
1 files changed, 25 insertions, 54 deletions
diff --git a/src/libostree/ostree-sysroot-cleanup.c b/src/libostree/ostree-sysroot-cleanup.c
index 181dbd16..2b5c3e68 100644
--- a/src/libostree/ostree-sysroot-cleanup.c
+++ b/src/libostree/ostree-sysroot-cleanup.c
@@ -138,67 +138,40 @@ parse_bootdir_name (const char *name,
static gboolean
list_all_boot_directories (OstreeSysroot *self,
- GPtrArray **out_bootdirs,
+ char ***out_bootdirs,
GCancellable *cancellable,
GError **error)
{
- gboolean ret = FALSE;
- g_autoptr(GFile) boot_ostree = NULL;
- g_autoptr(GPtrArray) ret_bootdirs = NULL;
- GError *temp_error = NULL;
+ g_autoptr(GPtrArray) ret_bootdirs = g_ptr_array_new_with_free_func (g_free);
- boot_ostree = g_file_resolve_relative_path (self->path, "boot/ostree");
-
- ret_bootdirs = g_ptr_array_new_with_free_func (g_object_unref);
-
- g_autoptr(GFileEnumerator) dir_enum =
- g_file_enumerate_children (boot_ostree, OSTREE_GIO_FAST_QUERYINFO,
- G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
- cancellable, &temp_error);
- if (!dir_enum)
- {
- if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
- {
- g_clear_error (&temp_error);
- goto done;
- }
- else
- {
- g_propagate_error (error, temp_error);
- goto out;
- }
- }
+ gboolean exists = FALSE;
+ g_auto(GLnxDirFdIterator) dfd_iter = { 0, };
+ if (self->boot_fd >= 0 && !ot_dfd_iter_init_allow_noent (self->boot_fd, "ostree", &dfd_iter, &exists, error))
+ return FALSE;
- while (TRUE)
+ while (exists)
{
- GFileInfo *file_info = NULL;
- GFile *child = NULL;
- const char *name;
-
- if (!g_file_enumerator_iterate (dir_enum, &file_info, &child,
- NULL, error))
- goto out;
- if (file_info == NULL)
+ struct dirent *dent;
+ if (!glnx_dirfd_iterator_next_dent_ensure_dtype (&dfd_iter, &dent, cancellable, error))
+ return FALSE;
+ if (dent == NULL)
break;
- if (g_file_info_get_file_type (file_info) != G_FILE_TYPE_DIRECTORY)
+ if (dent->d_type != DT_DIR)
continue;
/* Only look at directories ending in -CHECKSUM; nothing else
* should be in here, but let's be conservative.
*/
- name = g_file_info_get_name (file_info);
- if (!parse_bootdir_name (name, NULL, NULL))
+ if (!parse_bootdir_name (dent->d_name, NULL, NULL))
continue;
- g_ptr_array_add (ret_bootdirs, g_object_ref (child));
+ g_ptr_array_add (ret_bootdirs, g_strdup (dent->d_name));
}
- done:
- ret = TRUE;
- ot_transfer_out_value (out_bootdirs, &ret_bootdirs);
- out:
- return ret;
+ g_ptr_array_add (ret_bootdirs, NULL);
+ *out_bootdirs = (char**)g_ptr_array_free (g_steal_pointer (&ret_bootdirs), FALSE);
+ return TRUE;
}
/* A sysroot has at most one active "boot version" (pair of version,subversion)
@@ -332,25 +305,23 @@ cleanup_old_deployments (OstreeSysroot *self,
}
/* Clean up boot directories */
- g_autoptr(GPtrArray) all_boot_dirs = NULL;
- if (!list_all_boot_directories (self, &all_boot_dirs,
- cancellable, error))
+ g_auto(GStrv) all_boot_dirs = NULL;
+ if (!list_all_boot_directories (self, &all_boot_dirs, cancellable, error))
return FALSE;
- for (guint i = 0; i < all_boot_dirs->len; i++)
+ for (char **it = all_boot_dirs; it && *it; it++)
{
- GFile *bootdir = all_boot_dirs->pdata[i];
- g_autofree char *osname = NULL;
+ char *bootdir = *it;
g_autofree char *bootcsum = NULL;
- if (!parse_bootdir_name (glnx_basename (gs_file_get_path_cached (bootdir)),
- &osname, &bootcsum))
- g_assert_not_reached ();
+ if (!parse_bootdir_name (bootdir, NULL, &bootcsum))
+ g_assert_not_reached (); /* checked in list_all_boot_directories() */
if (g_hash_table_lookup (active_boot_checksums, bootcsum))
continue;
- if (!glnx_shutil_rm_rf_at (AT_FDCWD, gs_file_get_path_cached (bootdir), cancellable, error))
+ g_autofree char *subpath = g_build_filename ("ostree", bootdir, NULL);
+ if (!glnx_shutil_rm_rf_at (self->boot_fd, subpath, cancellable, error))
return FALSE;
}