Fix
This commit is contained in:
parent
d6a3c1785c
commit
082efef439
5 changed files with 63 additions and 6 deletions
32
Cargo.lock
generated
32
Cargo.lock
generated
|
@ -196,6 +196,7 @@ dependencies = [
|
|||
"log",
|
||||
"percent-encoding",
|
||||
"prettytable-rs",
|
||||
"stderrlog",
|
||||
"structopt",
|
||||
"thiserror",
|
||||
"walkdir",
|
||||
|
@ -434,6 +435,19 @@ version = "1.0.117"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b88fa983de7720629c9387e9f517353ed404164b1e482c970a90c1a4aaf7dc1a"
|
||||
|
||||
[[package]]
|
||||
name = "stderrlog"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b02f316286ae558d83acc93dd81eaba096e746987a7961d4a9ae026842bae67f"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"chrono",
|
||||
"log",
|
||||
"termcolor",
|
||||
"thread_local",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.8.0"
|
||||
|
@ -486,6 +500,15 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f"
|
||||
dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "textwrap"
|
||||
version = "0.11.0"
|
||||
|
@ -515,6 +538,15 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread_local"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.1.44"
|
||||
|
|
|
@ -19,6 +19,7 @@ libmount = "0.1"
|
|||
log = "0.4"
|
||||
percent-encoding = "2.1"
|
||||
prettytable-rs = "0.8.0"
|
||||
stderrlog = "0.5.0"
|
||||
structopt = "0.3"
|
||||
thiserror = "1.0"
|
||||
walkdir = "2.3"
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#![warn(missing_docs)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
#[macro_use]
|
||||
|
|
23
src/main.rs
23
src/main.rs
|
@ -6,6 +6,16 @@ use garbage::{
|
|||
};
|
||||
use structopt::StructOpt;
|
||||
|
||||
#[derive(StructOpt)]
|
||||
struct Opt {
|
||||
#[structopt(subcommand)]
|
||||
command: Command,
|
||||
|
||||
/// Verbosity (-v, -vv, -vvv, etc)
|
||||
#[structopt(short = "v", long = "verbose", parse(from_occurrences))]
|
||||
verbose: usize,
|
||||
}
|
||||
|
||||
#[derive(StructOpt)]
|
||||
enum Command {
|
||||
/// Empty a trash directory.
|
||||
|
@ -30,8 +40,7 @@ enum Command {
|
|||
Restore(RestoreOptions),
|
||||
}
|
||||
|
||||
fn run() -> Result<()> {
|
||||
let cmd = Command::from_args();
|
||||
fn run(cmd: Command) -> Result<()> {
|
||||
match cmd {
|
||||
Command::Empty(options) => ops::empty(options),
|
||||
Command::List(options) => ops::list(options),
|
||||
|
@ -41,7 +50,15 @@ fn run() -> Result<()> {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
match run() {
|
||||
let opt = Opt::from_args();
|
||||
|
||||
stderrlog::new()
|
||||
.module(module_path!())
|
||||
.verbosity(opt.verbose)
|
||||
.init()
|
||||
.unwrap();
|
||||
|
||||
match run(opt.command) {
|
||||
Ok(_) => (),
|
||||
Err(err) => {
|
||||
eprintln!("Error: {}", err);
|
||||
|
|
|
@ -66,13 +66,18 @@ pub struct PutOptions {
|
|||
/// Throw some files into the trash.
|
||||
pub fn put(options: PutOptions) -> Result<()> {
|
||||
for path in options.paths.iter() {
|
||||
let abs_path = utils::into_absolute(&path)?;
|
||||
|
||||
// don't allow deleting '.' or '..'
|
||||
let current_dir = env::current_dir()?;
|
||||
let parent = current_dir.parent();
|
||||
info!("Checking if {:?} is . or ..", abs_path);
|
||||
trace!("curr = {:?}", current_dir);
|
||||
trace!("parent = {:?}", parent);
|
||||
|
||||
if !(utils::into_absolute(&path)? == current_dir.as_path()
|
||||
if abs_path == current_dir.as_path()
|
||||
|| (current_dir.parent().is_some()
|
||||
&& utils::into_absolute(&path)?
|
||||
== current_dir.parent().unwrap()))
|
||||
&& abs_path == current_dir.parent().unwrap())
|
||||
{
|
||||
return Err(Error::Put(PutError::CannotTrashDotDirs));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue