diff --git a/Cargo.lock b/Cargo.lock index 0c36fef..d88b8b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -196,7 +196,7 @@ dependencies = [ [[package]] name = "boxxy" -version = "0.8.4" +version = "0.8.5" dependencies = [ "bat", "byteorder", @@ -209,6 +209,7 @@ dependencies = [ "dirs", "dotenv", "dotenv-parser", + "eyre", "grep", "haikunator", "lazy_static", @@ -693,9 +694,9 @@ dependencies = [ [[package]] name = "eyre" -version = "0.6.8" +version = "0.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c2b6b5a29c02cdc822728b7d7b8ae1bab3e3b05d44522770ddd49722eeac7eb" +checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec" dependencies = [ "indenter", "once_cell", diff --git a/Cargo.toml b/Cargo.toml index 42dfb67..62befa3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "boxxy" -version = "0.8.4" +version = "0.8.5" edition = "2021" repository = "https://github.com/queer/boxxy" @@ -21,6 +21,7 @@ daemonize = "0.5.0" dirs = "5.0.1" dotenv = "0.15.0" dotenv-parser = "0.1.3" +eyre = "0.6.12" grep = "0.3.1" haikunator = "0.1.2" lazy_static = "1.5.0" diff --git a/src/enclosure/fs.rs b/src/enclosure/fs.rs index 6fb6dc8..b7df2ae 100644 --- a/src/enclosure/fs.rs +++ b/src/enclosure/fs.rs @@ -2,6 +2,7 @@ use std::fs::{self, OpenOptions}; use std::path::{Path, PathBuf}; use color_eyre::Result; +use eyre::eyre; use log::*; use nix::mount::{mount, MsFlags}; @@ -62,6 +63,19 @@ impl FsDriver { fn bind_mount(&self, src: &Path, target: &Path, flags: MsFlags) -> Result<()> { debug!("bind mount {src:?} onto {target:?}"); + + // Ensure that `src` and `target` are the same type of file, erroring if they aren't + if src.is_dir() && !target.is_dir() { + return Err(eyre!( + "Cannot bind mount a directory onto a file: {src:?} -> {target:?}" + )); + } + if src.is_file() && !target.is_file() { + return Err(eyre!( + "Cannot bind mount a file onto a directory: {src:?} -> {target:?}" + )); + } + mount( Some(src), target, @@ -117,10 +131,7 @@ impl FsDriver { fn do_resolve_symlink(path: &Path, depth: u32) -> Result { if depth > 10 { - return Err(color_eyre::eyre::eyre!( - "Too many symlinks when resolving path: {:?}", - path - )); + return Err(eyre!("Too many symlinks when resolving path: {:?}", path)); } let path = if path.is_symlink() { diff --git a/src/enclosure/mod.rs b/src/enclosure/mod.rs index e4240cf..1a39c16 100644 --- a/src/enclosure/mod.rs +++ b/src/enclosure/mod.rs @@ -254,8 +254,8 @@ impl Enclosure { let rewrite_path = self.fs.fully_expand_path(&rule.rewrite)?; - debug!("ensuring path: {target_path:?}"); - debug!("rewriting to: {rewrite_path:?}"); + debug!("temp files: ensuring path: {target_path:?}"); + debug!("temp files: rewriting to: {rewrite_path:?}"); match rule.mode { RuleMode::File => { @@ -272,7 +272,7 @@ impl Enclosure { } } - debug!("rewrote base bath {rewrite_path:?} => {target_path:?}"); + debug!("temp files: rewrote base path {rewrite_path:?} => {target_path:?}"); } Ok(vec![]) @@ -336,8 +336,8 @@ impl Enclosure { let rewrite_path = self.fs.fully_expand_path(&rule.rewrite)?; - debug!("source exists: {}", rewrite_path.exists()); - debug!("target exists: {}", target_path.exists()); + debug!("rule apply: source exists: {}", rewrite_path.exists()); + debug!("rule apply: target exists: {}", target_path.exists()); // If the target file doesn't exist, we have to create it in order to bind mount over it. match rule.mode { @@ -359,7 +359,7 @@ impl Enclosure { } } - debug!("rewrote base bath {rewrite_path:?} => {target_path:?}"); + debug!("rule apply: rewrote base path {rewrite_path:?} => {target_path:?}"); } Ok(()) @@ -400,9 +400,7 @@ impl Enclosure { if path.exists() { path } else { - return Err(color_eyre::eyre::eyre!( - "could not resolve binary: {program:?}" - )); + return Err(eyre::eyre!("could not resolve binary: {program:?}")); } } } @@ -451,7 +449,7 @@ impl Enclosure { if found_appimage_extract && found_appimage_help && found_appimage_mount && !self_extracting { - return Err(color_eyre::eyre::eyre!( + return Err(eyre::eyre!( "{program:?} is an AppImage! Please extract it first with --appimage-extract. You can also use --appimage-extract-and-run. For more information, see https://github.com/AppImage/AppImageKit/wiki/FUSE#fallback", program = self.config.command.get_program() ));