OstreeMutableTree: add _remove method

There is no API method to remove a file or subdirectory from a MutableTree
besides directly manipulating the GHashTable returned by _get_files or
_get_subdirs. This isn't possible from an introspection binding that transforms
the returned GHashTable, and may also leave the tree checksum in an invalid
state. Introduce a new method so that removing files or subdirectories is
safe, and possible from bindings.

Closes: #1724
Approved by: jlebon
This commit is contained in:
Robert McQueen 2018-09-18 15:46:24 +01:00 committed by Atomic Bot
parent 6b37fe8310
commit b32c9e0df9
4 changed files with 53 additions and 0 deletions

View File

@ -257,6 +257,7 @@ ostree_mutable_tree_get_metadata_checksum
ostree_mutable_tree_set_contents_checksum
ostree_mutable_tree_get_contents_checksum
ostree_mutable_tree_replace_file
ostree_mutable_tree_remove
ostree_mutable_tree_ensure_dir
ostree_mutable_tree_lookup
ostree_mutable_tree_ensure_parent_dirs

View File

@ -19,6 +19,7 @@
/* Add new symbols here. Release commits should copy this section into -released.sym. */
LIBOSTREE_2018.9 {
ostree_mutable_tree_remove;
ostree_repo_get_min_free_space_bytes;
} LIBOSTREE_2018.7;

View File

@ -332,6 +332,51 @@ ostree_mutable_tree_replace_file (OstreeMutableTree *self,
return ret;
}
/**
* ostree_mutable_tree_remove:
* @self: Tree
* @name: Name of file or subdirectory to remove
* @allow_noent: If @FALSE, an error will be thrown if @name does not exist in the tree
* @error: a #GError
*
* Remove the file or subdirectory named @name from the mutable tree @self.
*/
gboolean
ostree_mutable_tree_remove (OstreeMutableTree *self,
const char *name,
gboolean allow_noent,
GError **error)
{
gboolean ret = FALSE;
g_return_val_if_fail (name != NULL, FALSE);
if (!ot_util_filename_validate (name, error))
goto out;
if (!_ostree_mutable_tree_make_whole (self, NULL, error))
goto out;
if (!g_hash_table_remove (self->files, name) &&
!g_hash_table_remove (self->subdirs, name))
{
if (allow_noent)
{
ret = TRUE;
goto out;
}
set_error_noent (error, name);
goto out;
}
invalidate_contents_checksum (self);
ret = TRUE;
out:
return ret;
}
/**
* ostree_mutable_tree_ensure_dir:
* @self: Tree

View File

@ -77,6 +77,12 @@ gboolean ostree_mutable_tree_replace_file (OstreeMutableTree *self,
const char *checksum,
GError **error);
_OSTREE_PUBLIC
gboolean ostree_mutable_tree_remove (OstreeMutableTree *self,
const char *name,
gboolean allow_noent,
GError **error);
_OSTREE_PUBLIC
gboolean ostree_mutable_tree_ensure_dir (OstreeMutableTree *self,
const char *name,