repo: Add ostree_repo_write_regfile

This API is push rather than pull, which makes it much more
suitable to use cases like parsing a tar file from external
code.

Now, we have a large mess in this area internally because
the original file writing code was pull based, but static
deltas hit the same problem of wanting a push API, so I added
this special `OstreeRepoBareContent` just for writing regular
files from a push API.

Eventually...I'd like to deprecate the pull based API,
and rework things so that for regular files the push API
is the default, and then `write_content_object()` would
be split up into archive/bare cases.

In this world the `ostree_repo_write_content()` API would
then need to hackily bridge pull to push and it'd be
less efficient.

Anyways for now due to this bifurcation, this API only
works on non-archive repositories, but that's fine for
now because that's what I want for the `ostree-ext-container`
bits.
This commit is contained in:
Colin Walters committed 2021-04-09 21:54:44 +00:00
1 parent 020f6cb652
commit 6f84aff0ae
11 files changed
+282 -8

No files matched your search

+33
View File
@@ -2855,6 +2855,39 @@ ostree_repo_write_symlink (OstreeRepo *self,
return ostree_checksum_from_bytes (csum);
}
/**
* ostree_repo_write_regfile:
* @self: Repo,
* @expected_checksum: (allow-none): Expected checksum (SHA-256 hex string)
* @uid: user id
* @gid: group id
* @mode: Unix file mode
* @content_len: Expected content length
* @xattrs: (allow-none): Extended attributes (GVariant type `(ayay)`)
* @error: Error
*
* Create an `OstreeContentWriter` that allows streaming output into
* the repository.
*
* Returns: (transfer full): A new writer, or %NULL on error
* Since: 2021.2
*/
OstreeContentWriter *
ostree_repo_write_regfile (OstreeRepo *self,
const char *expected_checksum,
guint32 uid,
guint32 gid,
guint32 mode,
guint64 content_len,
GVariant *xattrs,
GError **error)
{
if (self->mode == OSTREE_REPO_MODE_ARCHIVE)
return glnx_null_throw (error, "Cannot currently use ostree_repo_write_regfile() on an archive mode repository");
return _ostree_content_writer_new (self, expected_checksum, uid, gid, mode, content_len, xattrs, error);
}
typedef struct {
OstreeRepo *repo;
char *expected_checksum;