This commit is contained in:
2026-05-10 19:56:42 -05:00
parent bfd4814d70
commit 9d4a7952bc
+18 -6
View File
@@ -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());