Skip to content

Commit

Permalink
🐛 fix: 0.8.5: Log useful errors when unable to bind mount a rewrite o…
Browse files Browse the repository at this point in the history
…nto a target
  • Loading branch information
queer committed Jul 7, 2024
1 parent 8c6da25 commit 1f94d15
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
7 changes: 4 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "boxxy"
version = "0.8.4"
version = "0.8.5"
edition = "2021"
repository = "https://github.com/queer/boxxy"

Expand All @@ -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"
Expand Down
19 changes: 15 additions & 4 deletions src/enclosure/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -117,10 +131,7 @@ impl FsDriver {

fn do_resolve_symlink(path: &Path, depth: u32) -> Result<PathBuf> {
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() {
Expand Down
18 changes: 8 additions & 10 deletions src/enclosure/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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![])
Expand Down Expand Up @@ -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 {
Expand All @@ -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(())
Expand Down Expand Up @@ -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:?}"));
}
}
}
Expand Down Expand Up @@ -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()
));
Expand Down

0 comments on commit 1f94d15

Please sign in to comment.