1
0
mirror of https://github.com/containers/bootc.git synced 2026-02-05 15:45:53 +01:00

tar/export: Only load root once

Minor optimization for previous commit.

Signed-off-by: Colin Walters <walters@verbum.org>
This commit is contained in:
Colin Walters
2025-06-12 06:52:20 +02:00
parent 7658653aee
commit 76ec42bd91

View File

@@ -640,6 +640,7 @@ impl<'a, W: std::io::Write> OstreeTarWriter<'a, W> {
fn write_parents_of(
&mut self,
path: &Utf8Path,
root: &gio::File,
cache: &mut HashSet<Utf8PathBuf>,
) -> Result<()> {
let Some(parent) = path.parent() else {
@@ -654,15 +655,11 @@ impl<'a, W: std::io::Write> OstreeTarWriter<'a, W> {
return Ok(());
}
self.write_parents_of(parent, cache)?;
self.write_parents_of(parent, root, cache)?;
let inserted = cache.insert(parent.to_owned());
debug_assert!(inserted);
let root = self
.repo
.read_commit(&self.commit_checksum, gio::Cancellable::NONE)?
.0;
let parent_file = root.resolve_relative_path(unmap_path(parent).as_ref());
let queryattrs = "unix::*";
let queryflags = gio::FileQueryInfoFlags::NOFOLLOW_SYMLINKS;
@@ -733,13 +730,17 @@ fn write_chunk<W: std::io::Write>(
create_parent_dirs: bool,
) -> Result<()> {
let mut cache = std::collections::HashSet::new();
let root = writer
.repo
.read_commit(&writer.commit_checksum, gio::Cancellable::NONE)?
.0;
for (checksum, (_size, paths)) in chunk.into_iter() {
let (objpath, h) = writer.append_content(checksum.borrow())?;
for path in paths.iter() {
let path = path_for_tar_v1(path);
let h = h.clone();
if create_parent_dirs {
writer.write_parents_of(&path, &mut cache)?;
writer.write_parents_of(&path, &root, &mut cache)?;
}
writer.append_content_hardlink(&objpath, h, path)?;
}