diff options
| author | Hermes Agent <hermes@localhost> | 2026-08-12 07:48:21 +0000 |
|---|---|---|
| committer | Hermes Agent <hermes@localhost> | 2026-08-12 07:48:21 +0000 |
| commit | f967d698efd44473a9285e02d0109f3bb0641622 (patch) | |
| tree | c94975571db9426cf71b15c9e6d16346e438c7c6 /src/archive.rs | |
| parent | 5e6cae20331f8e7cfd551b4656f0de852a4ad44c (diff) | |
Format native builder and satisfy clippy
Diffstat (limited to 'src/archive.rs')
| -rw-r--r-- | src/archive.rs | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/src/archive.rs b/src/archive.rs index c0a2195..fd4d899 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -3,7 +3,7 @@ use std::fs::{self, File, OpenOptions}; use std::os::unix::fs::MetadataExt; use std::path::{Path, PathBuf}; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use tar::{Builder, EntryType, Header}; /// Writes a deterministic rootfs tar archive using numeric ownership metadata. @@ -28,7 +28,10 @@ impl NativeTarWriter { let output = output.as_ref(); reject_output_inside_rootfs(rootfs, output)?; if output.exists() { - bail!("archive output already exists; refusing to overwrite it: {}", output.display()); + bail!( + "archive output already exists; refusing to overwrite it: {}", + output.display() + ); } let temporary = temporary_output_path(output)?; let result = (|| { @@ -67,9 +70,12 @@ fn reject_output_inside_rootfs(rootfs: &Path, output: &Path) -> Result<()> { .canonicalize() .with_context(|| format!("canonicalize rootfs {}", rootfs.display()))?; let output_parent = output.parent().unwrap_or_else(|| Path::new(".")); - let output_parent = output_parent - .canonicalize() - .with_context(|| format!("canonicalize archive output parent {}", output_parent.display()))?; + let output_parent = output_parent.canonicalize().with_context(|| { + format!( + "canonicalize archive output parent {}", + output_parent.display() + ) + })?; if output_parent.starts_with(&rootfs) { bail!( "archive output must not be inside rootfs: {} is below {}", @@ -81,9 +87,9 @@ fn reject_output_inside_rootfs(rootfs: &Path, output: &Path) -> Result<()> { } fn temporary_output_path(output: &Path) -> Result<PathBuf> { - let name = output - .file_name() - .ok_or_else(|| anyhow::anyhow!("archive output path has no filename: {}", output.display()))?; + let name = output.file_name().ok_or_else(|| { + anyhow::anyhow!("archive output path has no filename: {}", output.display()) + })?; let mut temporary_name = name.to_os_string(); temporary_name.push(".partial"); Ok(output.with_file_name(temporary_name)) @@ -139,7 +145,11 @@ fn deterministic_header(metadata: &fs::Metadata, entry_type: EntryType, size: u6 header } -fn append_directory(archive: &mut Builder<File>, path: &Path, metadata: &fs::Metadata) -> Result<()> { +fn append_directory( + archive: &mut Builder<File>, + path: &Path, + metadata: &fs::Metadata, +) -> Result<()> { let mut header = deterministic_header(metadata, EntryType::Directory, 0); archive .append_data(&mut header, path, std::io::empty()) @@ -158,7 +168,8 @@ fn append_file( return append_hardlink(archive, path, target, metadata); } let mut header = deterministic_header(metadata, EntryType::Regular, metadata.len()); - let input = File::open(source).with_context(|| format!("open rootfs file {}", source.display()))?; + let input = + File::open(source).with_context(|| format!("open rootfs file {}", source.display()))?; archive .append_data(&mut header, path, input) .with_context(|| format!("append file {}", path.display()))?; @@ -184,7 +195,8 @@ fn append_symlink( path: &Path, metadata: &fs::Metadata, ) -> Result<()> { - let target = fs::read_link(source).with_context(|| format!("read rootfs symlink {}", source.display()))?; + let target = fs::read_link(source) + .with_context(|| format!("read rootfs symlink {}", source.display()))?; let mut header = deterministic_header(metadata, EntryType::Symlink, 0); archive .append_link(&mut header, path, target) |