diff --git a/crates/treehouse/src/cli/fix.rs b/crates/treehouse/src/cli/fix.rs index e6db536..b5e1342 100644 --- a/crates/treehouse/src/cli/fix.rs +++ b/crates/treehouse/src/cli/fix.rs @@ -146,16 +146,17 @@ pub fn fix_file_cli(fix_args: FixArgs, root: &dyn Dir) -> anyhow::Result { let mut treehouse = Treehouse::new(); let mut diagnostics = vec![]; let file_id = treehouse.add_file(fix_args.file.clone(), Source::Other(file)); - let edit_path = vfs::query::(root, &fix_args.file).ok_or_else(|| { - anyhow!( - "{} is not an editable file (perhaps it is not in a persistent path?)", - fix_args.file - ) - })?; Ok( if let Ok(fixed) = fix_file(&mut treehouse, &mut diagnostics, file_id) { if fix_args.apply { + let edit_path = vfs::query::(root, &fix_args.file).ok_or_else(|| { + anyhow!( + "{} is not an editable file (perhaps it is not in a persistent path?)", + fix_args.file + ) + })?; + // Try to write the backup first. If writing that fails, bail out without overwriting // the source file. if let Some(backup_path) = fix_args.backup { diff --git a/crates/treehouse/src/main.rs b/crates/treehouse/src/main.rs index 4ccd8b3..44c781c 100644 --- a/crates/treehouse/src/main.rs +++ b/crates/treehouse/src/main.rs @@ -92,7 +92,7 @@ async fn fallible_main( serve(sources, dirs, AsyncDir::new(target), serve_args.port).await?; } - Command::Fix(fix_args) => fix_file_cli(fix_args, &*dirs.content)?.apply().await?, + Command::Fix(fix_args) => fix_file_cli(fix_args, &*dirs.root)?.apply().await?, Command::FixAll(fix_args) => fix_all_cli(fix_args, &*dirs.content)?.apply().await?, Command::Wc(wc_args) => wc_cli(&dirs.content, wc_args)?, diff --git a/crates/treehouse/src/vfs/physical.rs b/crates/treehouse/src/vfs/physical.rs index 876333b..2cd9867 100644 --- a/crates/treehouse/src/vfs/physical.rs +++ b/crates/treehouse/src/vfs/physical.rs @@ -59,8 +59,9 @@ impl PhysicalDir { #[instrument("PhysicalDir::content", skip(self))] fn content(&self, path: &VPath) -> Option { - std::fs::read(self.root.join(physical_path(path))) - .inspect_err(|err| error!("{self:?} cannot read file at vpath {path:?}: {err:?}",)) + let physical_path = self.root.join(physical_path(path)); + std::fs::read(&physical_path) + .inspect_err(|err| error!("{self:?} cannot read file at vpath {path:?} / physical {physical_path:?}: {err:?}",)) .ok() .map(|bytes| { Content::new(