tweak
This commit is contained in:
+18
-6
@@ -86,14 +86,17 @@ where
|
|||||||
}
|
}
|
||||||
Command::Close { drawer_file, target_path, key } => {
|
Command::Close { drawer_file, target_path, key } => {
|
||||||
let key = resolve_key(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 {
|
Ok(DrawerOperation {
|
||||||
operation_type: OperationType::Close,
|
operation_type: OperationType::Close,
|
||||||
drawer_file,
|
drawer_file,
|
||||||
key,
|
key,
|
||||||
target_path: target,
|
target_path: target,
|
||||||
force: false,
|
force: false,
|
||||||
target_inferred: false,
|
target_inferred
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Command::Key { filename } => {
|
Command::Key { filename } => {
|
||||||
@@ -127,9 +130,6 @@ impl DrawerOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn perform_open(&self) -> Result<(), DrawerError> {
|
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)
|
let encrypted = std::fs::read(&self.drawer_file)
|
||||||
.map_err(|_| DrawerError::DrawerFileNotFound(self.drawer_file.clone()))?;
|
.map_err(|_| DrawerError::DrawerFileNotFound(self.drawer_file.clone()))?;
|
||||||
|
|
||||||
@@ -258,6 +258,9 @@ impl DrawerOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn validate_open(&self) -> Result<(), DrawerError> {
|
fn validate_open(&self) -> Result<(), DrawerError> {
|
||||||
|
if self.target_inferred {
|
||||||
|
println!("(assuming into {})", self.target_path.display());
|
||||||
|
}
|
||||||
if !self.drawer_file.exists() {
|
if !self.drawer_file.exists() {
|
||||||
return Err(DrawerError::DrawerFileNotFound(self.drawer_file.clone()));
|
return Err(DrawerError::DrawerFileNotFound(self.drawer_file.clone()));
|
||||||
}
|
}
|
||||||
@@ -281,6 +284,9 @@ impl DrawerOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn validate_close(&self) -> Result<(), DrawerError> {
|
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)
|
let meta = std::fs::metadata(&self.target_path)
|
||||||
.map_err(|_| DrawerError::TargetInvalid(self.target_path.clone()))?;
|
.map_err(|_| DrawerError::TargetInvalid(self.target_path.clone()))?;
|
||||||
if !meta.is_dir() {
|
if !meta.is_dir() {
|
||||||
@@ -291,7 +297,13 @@ impl DrawerOperation {
|
|||||||
}
|
}
|
||||||
let canon_target = self.target_path.canonicalize()
|
let canon_target = self.target_path.canonicalize()
|
||||||
.unwrap_or_else(|_| self.target_path.clone());
|
.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()
|
let canon_drawer = drawer_parent.canonicalize()
|
||||||
.unwrap_or_else(|_| drawer_parent.to_path_buf())
|
.unwrap_or_else(|_| drawer_parent.to_path_buf())
|
||||||
.join(self.drawer_file.file_name().unwrap_or_default());
|
.join(self.drawer_file.file_name().unwrap_or_default());
|
||||||
|
|||||||
Reference in New Issue
Block a user