Skip to content

ostree: Add support for exporting an ostree commit to a local ostree repo#347

Open
alexlarsson wants to merge 3 commits into
mainfrom
ostree-export
Open

ostree: Add support for exporting an ostree commit to a local ostree repo#347
alexlarsson wants to merge 3 commits into
mainfrom
ostree-export

Conversation

@alexlarsson

Copy link
Copy Markdown
Contributor

This will allow sync:ing a composefs repo with an ostree repo. Export of file objects tries to use reflink if possible.

cgwalters
cgwalters previously approved these changes Jul 2, 2026

@cgwalters cgwalters left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nonblocking here but just a reminder, I think we want a varlink API for this

Comment thread crates/composefs-ostree/src/repo.rs Outdated
Comment on lines +1372 to +1376
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)?;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/stored/checksummed/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We seem not to be validating this? Arguably we should by default?

The libostree code does have a "trusted" import path that doesn't.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

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>
@cgwalters cgwalters added this pull request to the merge queue Jul 6, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants