MCPcopy Create free account
hub / github.com/f0rr0/oliphaunt / append_tree

Function append_tree

xtask/src/main.rs:9350–9398  ·  view source on GitHub ↗
(
    builder: &mut tar::Builder<W>,
    root: &Path,
    current: &Path,
    archive_root: &Path,
)

Source from the content-addressed store, hash-verified

9348}
9349
9350fn append_tree<W: io::Write>(
9351 builder: &mut tar::Builder<W>,
9352 root: &Path,
9353 current: &Path,
9354 archive_root: &Path,
9355) -> Result<()> {
9356 let relative = current
9357 .strip_prefix(root)
9358 .with_context(|| format!("strip {} from {}", root.display(), current.display()))?;
9359 let archive_path = if relative.as_os_str().is_empty() {
9360 archive_root.to_path_buf()
9361 } else {
9362 archive_root.join(relative)
9363 };
9364
9365 if !archive_path.as_os_str().is_empty() {
9366 let mut header = tar::Header::new_gnu();
9367 header.set_mtime(0);
9368 header.set_uid(0);
9369 header.set_gid(0);
9370 header.set_username("root").ok();
9371 header.set_groupname("root").ok();
9372 if current.is_dir() {
9373 header.set_entry_type(tar::EntryType::Directory);
9374 header.set_mode(0o755);
9375 header.set_size(0);
9376 header.set_cksum();
9377 builder
9378 .append_data(&mut header, &archive_path, io::empty())
9379 .with_context(|| format!("append directory {}", archive_path.display()))?;
9380 } else if current.is_file() {
9381 let bytes = fs::read(current).with_context(|| format!("read {}", current.display()))?;
9382 header.set_entry_type(tar::EntryType::Regular);
9383 header.set_mode(if is_executable(current) { 0o755 } else { 0o644 });
9384 header.set_size(bytes.len() as u64);
9385 header.set_cksum();
9386 builder
9387 .append_data(&mut header, &archive_path, bytes.as_slice())
9388 .with_context(|| format!("append file {}", archive_path.display()))?;
9389 }
9390 }
9391
9392 if current.is_dir() {
9393 for child in sorted_children(current)? {
9394 append_tree(builder, root, &child, archive_root)?;
9395 }
9396 }
9397 Ok(())
9398}
9399
9400fn copy_tree_filtered(
9401 source: &Path,

Callers 1

deterministic_tar_zstFunction · 0.85

Calls 4

is_executableFunction · 0.85
sorted_childrenFunction · 0.85
lenMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected