mirror of
https://github.com/nivekuil/rip
synced 2024-09-20 05:51:54 +00:00
Canonicalize non-symlink paths
This commit is contained in:
parent
f987ff53cc
commit
144fb35dba
2 changed files with 47 additions and 45 deletions
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "rm-improved"
|
||||
version = "0.11.0"
|
||||
version = "0.11.1"
|
||||
authors = ["mail@nivekuil.com"]
|
||||
description = "rip: a safe and ergonomic alternative to rm"
|
||||
repository = "https://github.com/nivekuil/rip"
|
||||
|
|
20
src/main.rs
20
src/main.rs
|
@ -153,10 +153,14 @@ Send files to the graveyard (/tmp/graveyard-$USER by default) instead of unlinki
|
|||
|
||||
if let Some(targets) = matches.values_of("TARGET") {
|
||||
for target in targets {
|
||||
let source: &Path = &cwd.join(Path::new(target));
|
||||
|
||||
// Check if source exists
|
||||
if let Ok(metadata) = source.symlink_metadata() {
|
||||
if let Ok(metadata) = fs::symlink_metadata(target) {
|
||||
// Canonicalize the path unless it's a symlink
|
||||
let source = &if !metadata.file_type().is_symlink() {
|
||||
cwd.join(target).canonicalize().expect("Failed to canonicalize")
|
||||
} else {
|
||||
cwd.join(target)
|
||||
};
|
||||
|
||||
if matches.is_present("inspect") {
|
||||
if metadata.is_dir() {
|
||||
|
@ -197,11 +201,6 @@ Send files to the graveyard (/tmp/graveyard-$USER by default) instead of unlinki
|
|||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
println!("Cannot remove {}: no such file or directory", target);
|
||||
return;
|
||||
}
|
||||
|
||||
// If rip is called on a file already in the graveyard, prompt
|
||||
// to permanently delete it instead.
|
||||
if source.starts_with(graveyard) {
|
||||
|
@ -233,6 +232,9 @@ Send files to the graveyard (/tmp/graveyard-$USER by default) instead of unlinki
|
|||
} else if let Err(e) = write_log(source, dest, record) {
|
||||
println!("Error adding {} to record: {}", target, e);
|
||||
}
|
||||
} else {
|
||||
println!("Cannot remove {}: no such file or directory", target);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
println!("{}\nrip -h for help", matches.usage());
|
||||
|
@ -262,7 +264,7 @@ fn bury<S: AsRef<Path>, D: AsRef<Path>>(source: S, dest: D) -> io::Result<()> {
|
|||
}
|
||||
|
||||
// If that didn't work, then copy and rm.
|
||||
let parent = dest.parent().ok_or(io::Error::last_os_error())?;
|
||||
let parent = dest.parent().ok_or_else(|| io::Error::from(io::ErrorKind::NotFound))?;
|
||||
fs::create_dir_all(parent)?;
|
||||
|
||||
if fs::symlink_metadata(source)?.is_dir() {
|
||||
|
|
Loading…
Reference in a new issue