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

+36 -7
View File
@@ -27,6 +27,22 @@ function assertEquals(a, b) {
throw new Error("assertion failed " + JSON.stringify(a) + " == " + JSON.stringify(b));
}
function assertThrows(s, f) {
let success = false;
try {
f();
success = true;
} catch(e) {
let msg = e.toString();
if (msg.indexOf(s) == -1) {
throw new Error("Error message didn't match '" + s + "': " + msg)
}
}
if (success) {
throw new Error("Function was expected to throw, but didn't")
}
}
print('1..1')
let testDataDir = Gio.File.new_for_path('test-data');
@@ -51,18 +67,14 @@ print("commit => " + commit);
// Test direct write APIs
let inline_content = "default 0.0.0.0\nloopback 127.0.0.0\nlink-local 169.254.0.0\n";
let networks_checksum = "8aaa9dc13a0c5839fe4a277756798c609c53fac6fa2290314ecfef9041065873";
let regfile_mode = 33188; // 0o100000 | 0o644 (but in decimal so old gjs works)
let inline_checksum = repo.write_regfile_inline(null, 0, 0, regfile_mode, null, inline_content, null);
assertEquals(inline_checksum, "8aaa9dc13a0c5839fe4a277756798c609c53fac6fa2290314ecfef9041065873");
let written = false;
try {
assertThrows("Corrupted file object", function() {
// Changed an a to b from above to make the checksum not match
repo.write_regfile_inline("8baa9dc13a0c5839fe4a277756798c609c53fac6fa2290314ecfef9041065873", 0, 0, regfile_mode, null, inline_content, null);
written = true;
} catch (e) {
}
if (written)
throw new Error("Wrote invalid checksum");
});
repo.commit_transaction(null, null);
@@ -85,4 +97,21 @@ repo.commit_transaction(null, null);
[,readCommit] = repo.resolve_rev('someref', true);
assertEquals(readCommit, null);
// Test direct write API for regular files
let clen = inline_content.length;
assertThrows("Cannot currently use", function() {
let w = repo.write_regfile(null, 0, 0, regfile_mode, clen, null);
});
let bareRepoPath = Gio.File.new_for_path('repo');
let repo_bareu = OSTree.Repo.new(Gio.File.new_for_path('repo-bare'));
repo_bareu.create(OSTree.RepoMode.BARE_USER_ONLY, null);
let w = repo_bareu.write_regfile(null, 0, 0, regfile_mode, clen, null);
// Test multiple write() calls
w.write(inline_content.slice(0, 4), null)
w.write(inline_content.slice(4, 10), null)
w.write(inline_content.slice(10), null)
let actual_checksum = w.finish(null)
assertEquals(actual_checksum, networks_checksum)
print("ok test-core");
-1
View File
@@ -241,7 +241,6 @@ test_write_regfile_api (Fixture *fixture,
g_clear_pointer (&xattrs, g_variant_unref);
g_variant_builder_init (&xattrs_builder, (GVariantType*)"a(ayay)");
g_variant_builder_add (&xattrs_builder, "(^ay^ay)", "security.selinux", "system_u:object_r:bin_t:s0");
g_clear_pointer (&xattrs, g_variant_unref);
xattrs = g_variant_ref_sink (g_variant_builder_end (&xattrs_builder));
g_clear_pointer (&checksum, g_free);