mirror of
https://github.com/nivekuil/rip
synced 2024-11-23 04:03:03 +00:00
Give user the option to delete special files
This commit is contained in:
parent
cf4c80246c
commit
fce8cdf507
1 changed files with 13 additions and 2 deletions
13
src/main.rs
13
src/main.rs
|
@ -187,8 +187,19 @@ fn bury(source: &Path, dest: &Path) -> std::io::Result<()> {
|
|||
return Err(e);
|
||||
}
|
||||
} else {
|
||||
// Special file: Try copying it as normal, but this probably won't work
|
||||
let parent = dest.parent().unwrap();
|
||||
fs::create_dir_all(parent).expect("Failed to create grave path");
|
||||
if let Err(e) = fs::copy(source, dest) {
|
||||
println!("Non-regular file or directory: {}", source.display());
|
||||
try!(fs::copy(source, &dest));
|
||||
if !prompt_yes("Permanently delete the file?") {
|
||||
return Err(e);
|
||||
}
|
||||
// Create a dummy file to act as a marker in the graveyard
|
||||
let mut marker = try!(fs::File::create(dest));
|
||||
try!(marker.write_all(b"This is a marker for a file that was per\
|
||||
manently deleted. Requiescat in pace."));
|
||||
}
|
||||
try!(fs::remove_file(source));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue