diff options
author | Colin Walters <walters@verbum.org> | 2021-04-07 21:03:15 +0000 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2021-04-08 14:57:33 +0000 |
commit | 4e2a14eb0c92e38c533c453f6e375953a7208f0e (patch) | |
tree | e853be42bcbab68c56fda3f1a5b9581064cdcf26 /src/libostree/ostree-repo-commit.c | |
parent | b5c21defe9a66d601941a2408fd1aca310588108 (diff) | |
download | ostree-4e2a14eb0c92e38c533c453f6e375953a7208f0e.tar.gz |
repo: Add ostree_repo_write_regfile_inline
When working on ostree-ext and importing from tar, it's
quite inefficient and awkward for small files to end up creating
a whole `GInputStream` and `GFileInfo` and etc. for small files.
Plus the gtk-rs binding API to map from `impl Read` to Gio
https://docs.rs/gio/0.9.1/gio/struct.ReadInputStream.html
requires that the input stream is `Send` but the Rust `tar` API
isn't.
This is only 1/3 of the problem; we also need similar APIs
to directly create a symlink, and to stream large objects via
a push-based API.
Diffstat (limited to 'src/libostree/ostree-repo-commit.c')
-rw-r--r-- | src/libostree/ostree-repo-commit.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c index 9d5c6d3b..409738ad 100644 --- a/src/libostree/ostree-repo-commit.c +++ b/src/libostree/ostree-repo-commit.c @@ -2769,6 +2769,51 @@ ostree_repo_write_content (OstreeRepo *self, cancellable, error); } +/** + * ostree_repo_write_regfile_inline: + * @self: repo + * @expected_checksum: (allow-none): The expected checksum + * @uid: User id + * @gid: Group id + * @mode: File mode + * @xattrs: (allow-none): Extended attributes, GVariant of type (ayay) + * @buf: (array length=len) (element-type guint8): File contents + * @cancellable: Cancellable + * @error: Error + * + * Synchronously create a file object from the provided content. This API + * is intended for small files where it is reasonable to buffer the entire + * content in memory. + * + * Unlike `ostree_repo_write_content()`, if @expected_checksum is provided, + * this function will not check for the presence of the object beforehand. + * + * Returns: (transfer full): Checksum (as a hex string) of the committed file + * Since: 2021.2 + */ +_OSTREE_PUBLIC +char * +ostree_repo_write_regfile_inline (OstreeRepo *self, + const char *expected_checksum, + guint32 uid, + guint32 gid, + guint32 mode, + GVariant *xattrs, + const guint8* buf, + gsize len, + GCancellable *cancellable, + GError **error) +{ + g_autoptr(GInputStream) memin = g_memory_input_stream_new_from_data (buf, len, NULL); + g_autoptr(GFileInfo) finfo = _ostree_mode_uidgid_to_gfileinfo (mode, uid, gid); + g_autofree guint8* csum = NULL; + if (!write_content_object (self, expected_checksum, + memin, finfo, xattrs, &csum, + cancellable, error)) + return NULL; + return ostree_checksum_from_bytes (csum); +} + typedef struct { OstreeRepo *repo; char *expected_checksum; |