diff options
Diffstat (limited to 'src/rootfs.rs')
| -rw-r--r-- | src/rootfs.rs | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/src/rootfs.rs b/src/rootfs.rs index ea7d87b..79406a7 100644 --- a/src/rootfs.rs +++ b/src/rootfs.rs @@ -3,9 +3,9 @@ use std::fs; use std::os::unix::fs::symlink; use std::path::{Path, PathBuf}; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; -use crate::files::{relative_symlink_is_safe, RootfsPath}; +use crate::files::{RootfsPath, relative_symlink_is_safe}; #[derive(Debug, Clone, PartialEq, Eq)] pub struct CopyTree { @@ -127,7 +127,13 @@ fn copy_tree(rootfs: &Path, copy: &CopyTree, manifest: &mut MutationManifest) -> if !copy.source.is_dir() { bail!("copy source is not a directory: {}", copy.source.display()); } - copy_entry(rootfs, ©.source, copy.destination.as_path(), Path::new(""), manifest) + copy_entry( + rootfs, + ©.source, + copy.destination.as_path(), + Path::new(""), + manifest, + ) } fn copy_entry( @@ -196,7 +202,11 @@ fn write_file( Ok(()) } -fn enable_service(rootfs: &Path, service: &ServiceName, manifest: &mut MutationManifest) -> Result<()> { +fn enable_service( + rootfs: &Path, + service: &ServiceName, + manifest: &mut MutationManifest, +) -> Result<()> { let destination = RootfsPath::new(format!( "etc/systemd/system/multi-user.target.wants/{}", service.0 @@ -217,20 +227,28 @@ fn replace_with_file(source: &Path, output: &Path) -> Result<()> { Ok(metadata) if metadata.file_type().is_dir() => { bail!("cannot replace directory with file: {}", output.display()); } - Ok(_) => fs::remove_file(output).with_context(|| format!("replace {}", output.display()))?, + Ok(_) => { + fs::remove_file(output).with_context(|| format!("replace {}", output.display()))? + } Err(error) if error.kind() == std::io::ErrorKind::NotFound => {} Err(error) => return Err(error).with_context(|| format!("inspect {}", output.display())), } - fs::copy(source, output).with_context(|| format!("copy {} to {}", source.display(), output.display()))?; + fs::copy(source, output) + .with_context(|| format!("copy {} to {}", source.display(), output.display()))?; Ok(()) } fn replace_with_symlink(target: &Path, output: &Path) -> Result<()> { match fs::symlink_metadata(output) { Ok(metadata) if metadata.file_type().is_dir() => { - bail!("cannot replace directory with symlink: {}", output.display()); + bail!( + "cannot replace directory with symlink: {}", + output.display() + ); + } + Ok(_) => { + fs::remove_file(output).with_context(|| format!("replace {}", output.display()))? } - Ok(_) => fs::remove_file(output).with_context(|| format!("replace {}", output.display()))?, Err(error) if error.kind() == std::io::ErrorKind::NotFound => {} Err(error) => return Err(error).with_context(|| format!("inspect {}", output.display())), } |