Closed ericcornelissen closed 1 year ago
Thanks a lot for reporting and for investigating this! I think the fix is exactly what you describe, and I will publish a fix soon.
The fix was released in v3.0.3, such that it will now error if the path is empty. Please see the linked commit in case you have any suggestions on how to do that better.
Thank you for the fix (and quick response)! The implementation looks fine to me.
Calling
trash::delete("");
will result in the current working directory being deleted (tested on Ubuntu 22.04). I think this is unexpected because:std::path::Path::new("").exists()
returnsfalse
, whereas replacing""
with a file that does exist in the current working directory returnstrue
.std::fs::remove_dir("")
will not canonicalize the path to the current working directory, instead it will error with aNotFound
error.Any CLI program operating on the file system I tested complaints that
""
doesn't exist, e.g.:The behavior seems to originate from this logic:
https://github.com/Byron/trash-rs/blob/e20fe6ae94aa73d07ff31d911ad9ecf98b17f3a8/src/lib.rs#L226-L230
I'd guess adding an explicit check for a
""
path that returns an error would resolve the unexpected behavior, but I don't know the code base well enough to say if that makes sense.