From 9d4a7952bcc68dc5f2e49ab399e6a838b17ed67e Mon Sep 17 00:00:00 2001 From: Ross Andrews Date: Sun, 10 May 2026 19:56:42 -0500 Subject: [PATCH] tweak --- src/parsing.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/parsing.rs b/src/parsing.rs index 3352f4f..0afb063 100644 --- a/src/parsing.rs +++ b/src/parsing.rs @@ -86,14 +86,17 @@ where } Command::Close { drawer_file, target_path, key } => { let key = resolve_key(key); - let target = target_path.unwrap_or_else(|| PathBuf::from(".")); + let (target, target_inferred) = match target_path { + Some(p) => (p, false), + None => (PathBuf::from(drawer_file.file_stem().unwrap_or_default()), true), + }; Ok(DrawerOperation { operation_type: OperationType::Close, drawer_file, key, target_path: target, force: false, - target_inferred: false, + target_inferred }) } Command::Key { filename } => { @@ -127,9 +130,6 @@ impl DrawerOperation { } fn perform_open(&self) -> Result<(), DrawerError> { - if self.target_inferred { - println!("(assuming into {})", self.target_path.display()); - } let encrypted = std::fs::read(&self.drawer_file) .map_err(|_| DrawerError::DrawerFileNotFound(self.drawer_file.clone()))?; @@ -258,6 +258,9 @@ impl DrawerOperation { } fn validate_open(&self) -> Result<(), DrawerError> { + if self.target_inferred { + println!("(assuming into {})", self.target_path.display()); + } if !self.drawer_file.exists() { return Err(DrawerError::DrawerFileNotFound(self.drawer_file.clone())); } @@ -281,6 +284,9 @@ impl DrawerOperation { } fn validate_close(&self) -> Result<(), DrawerError> { + if self.target_inferred { + println!("(assuming from {})", self.target_path.display()); + } let meta = std::fs::metadata(&self.target_path) .map_err(|_| DrawerError::TargetInvalid(self.target_path.clone()))?; if !meta.is_dir() { @@ -291,7 +297,13 @@ impl DrawerOperation { } let canon_target = self.target_path.canonicalize() .unwrap_or_else(|_| self.target_path.clone()); - let drawer_parent = self.drawer_file.parent().unwrap_or(Path::new(".")); + let drawer_parent = match self.drawer_file.parent() { + None => Path::new("."), + Some(p) if p == Path::new("") => { + Path::new(".") + }, + Some(p) => p, + }; let canon_drawer = drawer_parent.canonicalize() .unwrap_or_else(|_| drawer_parent.to_path_buf()) .join(self.drawer_file.file_name().unwrap_or_default());