commit: Add _CONSUME modifier flag
For many cases of commit, we can actually optimize things by simply "adopting" the object rather than writing a new copy. For example, in rpm-ostree package layering. We can only make that optimization though if we take ownership of the file. This commit hence adds an API where a caller tells us to do so. For now, that just means we `unlink()` the files/dirs as we go, but we can now later add the "adopt" optimization. Closes: #1255 Approved by: jlebon
This commit is contained in:
1 parent
fc33ae018d
commit
bba7eb8069
6 files changed
+65
-1
No files matched your search
@@ -2589,9 +2589,22 @@ write_directory_content_to_mtree_internal (OstreeRepo *self,
|
||||
_ostree_repo_commit_modifier_apply (self, modifier, child_relpath, child_info, &modified_info);
|
||||
const gboolean child_info_was_modified = !_ostree_gfileinfo_equal (child_info, modified_info);
|
||||
|
||||
/* We currently only honor the CONSUME flag in the dfd_iter case to avoid even
|
||||
* more complexity in this function, and it'd mostly only be useful when
|
||||
* operating on local filesystems anyways.
|
||||
*/
|
||||
const gboolean delete_after_commit = dfd_iter && modifier &&
|
||||
(modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CONSUME);
|
||||
|
||||
if (filter_result != OSTREE_REPO_COMMIT_FILTER_ALLOW)
|
||||
{
|
||||
g_ptr_array_remove_index (path, path->len - 1);
|
||||
if (delete_after_commit)
|
||||
{
|
||||
g_assert (dfd_iter);
|
||||
if (!glnx_shutil_rm_rf_at (dfd_iter->fd, name, cancellable, error))
|
||||
return FALSE;
|
||||
}
|
||||
/* Note: early return */
|
||||
return TRUE;
|
||||
}
|
||||
@@ -2635,6 +2648,12 @@ write_directory_content_to_mtree_internal (OstreeRepo *self,
|
||||
modifier, path,
|
||||
cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
if (delete_after_commit)
|
||||
{
|
||||
if (!glnx_unlinkat (dfd_iter->fd, name, AT_REMOVEDIR, error))
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (repo_dir)
|
||||
@@ -2711,6 +2730,12 @@ write_directory_content_to_mtree_internal (OstreeRepo *self,
|
||||
error))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (delete_after_commit)
|
||||
{
|
||||
if (!glnx_unlinkat (dfd_iter->fd, name, 0, error))
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
g_ptr_array_remove_index (path, path->len - 1);
|
||||
@@ -2991,6 +3016,17 @@ ostree_repo_write_dfd_to_mtree (OstreeRepo *self,
|
||||
cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
/* And now finally remove the toplevel; see also the handling for this flag in
|
||||
* the write_dfd_iter_to_mtree_internal() function.
|
||||
*/
|
||||
const gboolean delete_after_commit = modifier &&
|
||||
(modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CONSUME);
|
||||
if (delete_after_commit)
|
||||
{
|
||||
if (!glnx_unlinkat (dfd, path, AT_REMOVEDIR, error))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user