ostree: Add support for exporting an ostree commit to a local ostree repo#347
ostree: Add support for exporting an ostree commit to a local ostree repo#347alexlarsson wants to merge 3 commits into
Conversation
c2f47b6 to
9e9cd2a
Compare
cgwalters
left a comment
There was a problem hiding this comment.
Cool! As expected I guess this is actually a pretty small amount of code...and now it's starting to feel rather within reach to just have a clean new Rust implementation of the ostree CLI from this crate too...
(Again leaving aside the OstreeSysroot stuff which is its own whole ball of stuff but...)
| println!("tagged {ref_name}"); | ||
| } | ||
| } | ||
| OstreeCommand::Export { |
There was a problem hiding this comment.
Nonblocking here but just a reminder, I think we want a varlink API for this
| if rustix::fs::ioctl_ficlone(&tmpfd, &fd).is_err() { | ||
| let mut src = File::from(fd); | ||
| let mut dst = File::from(tmpfd.try_clone()?); | ||
| std::io::copy(&mut src, &mut dst)?; | ||
| } |
There was a problem hiding this comment.
As far as I know std::io::copy always tries FICLONE internally by default anyways. The only value to making it explicit would be for us to track whether it worked or not (as the containers-storage import code does).
There was a problem hiding this comment.
I'll remove it for now then. We can be explicit later if we want.
| .context("Creating tmpfile for file object")?; | ||
|
|
||
| if is_symlink { | ||
| // bare-user: symlinks stored as regular files with target + NUL |
There was a problem hiding this comment.
No, it is stored that way, it it checksummed as part of the header gvariant.
| /// byte slice (for inline data). | ||
| pub fn write_file_object( | ||
| &self, | ||
| checksum: &Sha256Digest, |
There was a problem hiding this comment.
We seem not to be validating this? Arguably we should by default?
The libostree code does have a "trusted" import path that doesn't.
Adds object writing methods to LocalRepo (write_metadata_object, write_file_object, write_ref) supporting bare, bare-user, and bare-user-only modes with correct metadata ordering. The public export_commit() function walks the commit tree depth-first, writing file objects and dirmeta before dirtrees that reference them, and the commit object last. External file objects attempt reflink (ioctl_ficlone) before falling back to regular copy. All objects get mtime=0 matching ostree convention. Signed-off-by: Alexander Larsson <alexl@redhat.com>
Exports an ostree commit from the composefs repository to a standard ostree repository. Supports bare, bare-user, and bare-user-only destination repos. Signed-off-by: Alexander Larsson <alexl@redhat.com>
Tests exporting a composefs ostree commit to bare-user and bare-user-only destination repos, verifying with ostree fsck and rev-parse that the exported objects and refs are correct. The test content helper gains a bare_user_only flag to skip xattrs (which bare-user-only repos cannot store). Signed-off-by: Alexander Larsson <alexl@redhat.com>
9e9cd2a to
aa09131
Compare
This will allow sync:ing a composefs repo with an ostree repo. Export of file objects tries to use reflink if possible.