core: Unify object deletion code with prune

The prune API duplicated logic to delete objects, and furthermore the
core API to delete an object didn't clean up detached metadata.

Fix the duplication by doing the obvious thing: prune should call
_delete.

https://bugzilla.gnome.org/show_bug.cgi?id=733452
This commit is contained in:
Colin Walters 2014-07-20 08:35:58 -04:00
parent 1dd4435936
commit 72da2e0c36
2 changed files with 26 additions and 22 deletions

View File

@ -45,36 +45,24 @@ maybe_prune_loose_object (OtPruneData *data,
{
gboolean ret = FALSE;
gs_unref_variant GVariant *key = NULL;
gs_unref_object GFile *objf = NULL;
key = ostree_object_name_serialize (checksum, objtype);
objf = _ostree_repo_get_object_path (data->repo, checksum, objtype);
if (!g_hash_table_lookup_extended (data->reachable, key, NULL, NULL))
{
if (!(flags & OSTREE_REPO_PRUNE_FLAGS_NO_PRUNE))
{
gs_unref_object GFileInfo *info = NULL;
guint64 storage_size = 0;
if (!ot_gfile_query_info_allow_noent (objf, OSTREE_GIO_FAST_QUERYINFO,
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
&info, cancellable, error))
if (!ostree_repo_query_object_storage_size (data->repo, objtype, checksum,
&storage_size, cancellable, error))
goto out;
if (info)
{
if (objtype == OSTREE_OBJECT_TYPE_COMMIT)
{
gs_unref_object GFile *detached_metadata =
_ostree_repo_get_commit_metadata_loose_path (data->repo, checksum);
if (!ot_gfile_ensure_unlinked (detached_metadata, cancellable, error))
goto out;
}
if (!gs_file_unlink (objf, cancellable, error))
goto out;
data->freed_bytes += g_file_info_get_size (info);
}
if (!ostree_repo_delete_object (data->repo, objtype, checksum,
cancellable, error))
goto out;
data->freed_bytes += storage_size;
}
if (OSTREE_OBJECT_TYPE_IS_META (objtype))
data->n_unreachable_meta++;

View File

@ -1598,8 +1598,24 @@ ostree_repo_delete_object (OstreeRepo *self,
GCancellable *cancellable,
GError **error)
{
gs_unref_object GFile *objpath = _ostree_repo_get_object_path (self, sha256, objtype);
return gs_file_unlink (objpath, cancellable, error);
gboolean ret = FALSE;
gs_unref_object GFile *objpath = NULL;
if (objtype == OSTREE_OBJECT_TYPE_COMMIT)
{
gs_unref_object GFile *detached_metadata =
_ostree_repo_get_commit_metadata_loose_path (self, sha256);
if (!ot_gfile_ensure_unlinked (detached_metadata, cancellable, error))
goto out;
}
objpath = _ostree_repo_get_object_path (self, sha256, objtype);
if (!gs_file_unlink (objpath, cancellable, error))
goto out;
ret = TRUE;
out:
return ret;
}
/**