lib/prune: Complete porting to new code style
Only non-mechanical bit here was creating a local autoptr for a bit where we'd previously done an unref for a struct member. Closes: #847 Approved by: jlebon
This commit is contained in:
parent
63497c65f3
commit
986e05e3fd
|
|
@ -42,21 +42,14 @@ prune_commitpartial_file (OstreeRepo *repo,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
|
||||||
g_autofree char *path = _ostree_get_commitpartial_path (checksum);
|
g_autofree char *path = _ostree_get_commitpartial_path (checksum);
|
||||||
|
|
||||||
if (unlinkat (repo->repo_dir_fd, path, 0) != 0)
|
if (unlinkat (repo->repo_dir_fd, path, 0) != 0)
|
||||||
{
|
{
|
||||||
if (errno != ENOENT)
|
if (errno != ENOENT)
|
||||||
{
|
return glnx_throw_errno_prefix (error, "unlinkat");
|
||||||
glnx_set_error_from_errno (error);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = TRUE;
|
return TRUE;
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
|
@ -67,7 +60,6 @@ maybe_prune_loose_object (OtPruneData *data,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
|
||||||
g_autoptr(GVariant) key = NULL;
|
g_autoptr(GVariant) key = NULL;
|
||||||
|
|
||||||
key = ostree_object_name_serialize (checksum, objtype);
|
key = ostree_object_name_serialize (checksum, objtype);
|
||||||
|
|
@ -83,16 +75,16 @@ maybe_prune_loose_object (OtPruneData *data,
|
||||||
if (objtype == OSTREE_OBJECT_TYPE_COMMIT)
|
if (objtype == OSTREE_OBJECT_TYPE_COMMIT)
|
||||||
{
|
{
|
||||||
if (!prune_commitpartial_file (data->repo, checksum, cancellable, error))
|
if (!prune_commitpartial_file (data->repo, checksum, cancellable, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ostree_repo_query_object_storage_size (data->repo, objtype, checksum,
|
if (!ostree_repo_query_object_storage_size (data->repo, objtype, checksum,
|
||||||
&storage_size, cancellable, error))
|
&storage_size, cancellable, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
|
|
||||||
if (!ostree_repo_delete_object (data->repo, objtype, checksum,
|
if (!ostree_repo_delete_object (data->repo, objtype, checksum,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
|
|
||||||
data->freed_bytes += storage_size;
|
data->freed_bytes += storage_size;
|
||||||
}
|
}
|
||||||
|
|
@ -111,9 +103,7 @@ maybe_prune_loose_object (OtPruneData *data,
|
||||||
data->n_reachable_content++;
|
data->n_reachable_content++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = TRUE;
|
return TRUE;
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
|
@ -121,25 +111,22 @@ _ostree_repo_prune_tmp (OstreeRepo *self,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
|
||||||
g_auto(GLnxDirFdIterator) dfd_iter = { 0, };
|
|
||||||
glnx_fd_close int fd = -1;
|
|
||||||
|
|
||||||
if (self->cache_dir_fd == -1)
|
if (self->cache_dir_fd == -1)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
fd = glnx_opendirat_with_errno (self->cache_dir_fd, _OSTREE_SUMMARY_CACHE_DIR, FALSE);
|
glnx_fd_close int fd = glnx_opendirat_with_errno (self->cache_dir_fd, _OSTREE_SUMMARY_CACHE_DIR, FALSE);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
{
|
{
|
||||||
|
/* Note early return */
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT)
|
||||||
ret = TRUE;
|
return TRUE;
|
||||||
else
|
else
|
||||||
glnx_set_error_from_errno (error);
|
return glnx_throw_errno_prefix (error, "opendirat(%s)", _OSTREE_SUMMARY_CACHE_DIR);
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_auto(GLnxDirFdIterator) dfd_iter = { 0, };
|
||||||
if (!glnx_dirfd_iterator_init_take_fd (dup (fd), &dfd_iter, error))
|
if (!glnx_dirfd_iterator_init_take_fd (dup (fd), &dfd_iter, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
|
|
||||||
while (TRUE)
|
while (TRUE)
|
||||||
{
|
{
|
||||||
|
|
@ -148,8 +135,7 @@ _ostree_repo_prune_tmp (OstreeRepo *self,
|
||||||
struct dirent *dent;
|
struct dirent *dent;
|
||||||
|
|
||||||
if (!glnx_dirfd_iterator_next_dent (&dfd_iter, &dent, cancellable, error))
|
if (!glnx_dirfd_iterator_next_dent (&dfd_iter, &dent, cancellable, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
|
|
||||||
if (dent == NULL)
|
if (dent == NULL)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -167,17 +153,11 @@ _ostree_repo_prune_tmp (OstreeRepo *self,
|
||||||
dent->d_name[len - 4] = '.';
|
dent->d_name[len - 4] = '.';
|
||||||
|
|
||||||
if (unlinkat (fd, dent->d_name, 0) < 0)
|
if (unlinkat (fd, dent->d_name, 0) < 0)
|
||||||
{
|
return glnx_throw_errno_prefix (error, "unlinkat");
|
||||||
glnx_set_error_from_errno (error);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = TRUE;
|
return TRUE;
|
||||||
|
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -198,22 +178,17 @@ ostree_repo_prune_static_deltas (OstreeRepo *self, const char *commit,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
|
||||||
g_autoptr(GPtrArray) deltas = NULL;
|
g_autoptr(GPtrArray) deltas = NULL;
|
||||||
guint i;
|
|
||||||
|
|
||||||
if (!ostree_repo_list_static_delta_names (self, &deltas,
|
if (!ostree_repo_list_static_delta_names (self, &deltas,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
|
|
||||||
for (i = 0; i < deltas->len; i++)
|
for (guint i = 0; i < deltas->len; i++)
|
||||||
{
|
{
|
||||||
const char *deltaname = deltas->pdata[i];
|
const char *deltaname = deltas->pdata[i];
|
||||||
const char *dash = strchr (deltaname, '-');
|
const char *dash = strchr (deltaname, '-');
|
||||||
const char *to = NULL;
|
const char *to = NULL;
|
||||||
gboolean have_commit;
|
|
||||||
g_autofree char *from = NULL;
|
g_autofree char *from = NULL;
|
||||||
g_autofree char *deltadir = NULL;
|
|
||||||
|
|
||||||
if (!dash)
|
if (!dash)
|
||||||
{
|
{
|
||||||
|
|
@ -232,26 +207,24 @@ ostree_repo_prune_static_deltas (OstreeRepo *self, const char *commit,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
gboolean have_commit;
|
||||||
if (!ostree_repo_has_object (self, OSTREE_OBJECT_TYPE_COMMIT,
|
if (!ostree_repo_has_object (self, OSTREE_OBJECT_TYPE_COMMIT,
|
||||||
to, &have_commit,
|
to, &have_commit,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
|
|
||||||
if (have_commit)
|
if (have_commit)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_debug ("Trying to prune static delta %s", deltaname);
|
g_debug ("Trying to prune static delta %s", deltaname);
|
||||||
deltadir = _ostree_get_relative_static_delta_path (from, to, NULL);
|
g_autofree char *deltadir = _ostree_get_relative_static_delta_path (from, to, NULL);
|
||||||
|
|
||||||
if (!glnx_shutil_rm_rf_at (self->repo_dir_fd, deltadir,
|
if (!glnx_shutil_rm_rf_at (self->repo_dir_fd, deltadir,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = TRUE;
|
return TRUE;
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
|
@ -264,13 +237,14 @@ repo_prune_internal (OstreeRepo *self,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
|
||||||
GHashTableIter hash_iter;
|
GHashTableIter hash_iter;
|
||||||
gpointer key, value;
|
gpointer key, value;
|
||||||
OtPruneData data = { 0, };
|
OtPruneData data = { 0, };
|
||||||
|
|
||||||
data.repo = self;
|
data.repo = self;
|
||||||
data.reachable = g_hash_table_ref (options->reachable);
|
/* We unref this when we're done */
|
||||||
|
g_autoptr(GHashTable) reachable_owned = g_hash_table_ref (options->reachable);
|
||||||
|
data.reachable = reachable_owned;
|
||||||
|
|
||||||
g_hash_table_iter_init (&hash_iter, objects);
|
g_hash_table_iter_init (&hash_iter, objects);
|
||||||
while (g_hash_table_iter_next (&hash_iter, &key, &value))
|
while (g_hash_table_iter_next (&hash_iter, &key, &value))
|
||||||
|
|
@ -289,24 +263,20 @@ repo_prune_internal (OstreeRepo *self,
|
||||||
|
|
||||||
if (!maybe_prune_loose_object (&data, options->flags, checksum, objtype,
|
if (!maybe_prune_loose_object (&data, options->flags, checksum, objtype,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ostree_repo_prune_static_deltas (self, NULL, cancellable, error))
|
if (!ostree_repo_prune_static_deltas (self, NULL, cancellable, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
|
|
||||||
if (!_ostree_repo_prune_tmp (self, cancellable, error))
|
if (!_ostree_repo_prune_tmp (self, cancellable, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
|
|
||||||
ret = TRUE;
|
|
||||||
*out_objects_total = (data.n_reachable_meta + data.n_unreachable_meta +
|
*out_objects_total = (data.n_reachable_meta + data.n_unreachable_meta +
|
||||||
data.n_reachable_content + data.n_unreachable_content);
|
data.n_reachable_content + data.n_unreachable_content);
|
||||||
*out_objects_pruned = (data.n_unreachable_meta + data.n_unreachable_content);
|
*out_objects_pruned = (data.n_unreachable_meta + data.n_unreachable_content);
|
||||||
*out_pruned_object_size_total = data.freed_bytes;
|
*out_pruned_object_size_total = data.freed_bytes;
|
||||||
out:
|
return TRUE;
|
||||||
if (data.reachable)
|
|
||||||
g_hash_table_unref (data.reachable);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue