-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rm: fix issue #6620 (refuse to remove '.' and '..') #6623
base: main
Are you sure you want to change the base?
Conversation
I see this does the same thing as #6621 |
but tests/rm/r-4 is fixed in the other PR |
Thanks. Do you want me to close this out? Or which PR will get merged? |
the other PR code is a bit more complex. |
8d2821a
to
cfc82c6
Compare
GNU testsuite comparison:
|
@just-an-engineer what is your plan wrt this PR? |
We can merge this one if @AnirbanHalder654322 doesn't have any progress on the other PR, since I already have it working without regex, it already works on Windows, and since I made them a coauthor on the commits. But if they responds and pushes whatever changes, I'll leave it to you or them, but if the other one gets merged, I can just close this one. |
@sylvestre, I'm marking this as a draft, and I'll close it out once @AnirbanHalder654322 PR gets merged. His is starting to look a bit cleaner and more fleshed out than mine. Particularly with removing trailing slashes, and more comprehensive tests, in my opinion. |
if path | ||
.to_str() | ||
.unwrap() | ||
.ends_with(format!("{}.", del).as_str()) | ||
|| path | ||
.to_str() | ||
.unwrap() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The conversion is done twice. That's not a big deal, but maybe just saving the result in a variable is easy enough to avoid doing the same work twice?
.to_str().unwrap()
will cause problems with non-UTF-8 filenames. Please consider using os_str_as_bytes: If it works great (and add a test), if it doesn't (or is too much work or feels out of scope) then disregard this suggestion.- I'm not sure whether this is the right condition. Maybe a trailing path separator ("del") should count, too? Here's a small example that demonstrates the difference:
As you can see, we still delete a directory, causing a confusing error message. I'm not sure whether it suffices to add the two conditions
$ rm -rf foo && mkdir -p foo/bar/baz && rm -rf foo/bar/baz/../ rm: refusing to remove '.' or '..' directory: skipping 'foo/bar/baz/../' [$? = 1] $ find foo/ foo/ foo/bar foo/bar/baz $ rm -rf foo && mkdir -p foo/bar/baz && cargo run -q --features rm rm -rf foo/bar/baz/../ rm: cannot remove 'foo/bar/baz/../': No such file or directory (os error 2) [$? = 1] $ find foo foo foo/bar
ends_with("/./")
and ".ends_with("/../")". Can you find any other edge cases?
@just-an-engineer it is still marked as draft, are you still working on it? thanks |
Co-authored-by: Anirban Halder <[email protected]>
Co-authored-by: Anirban Halder <[email protected]>
b09f50e
to
d894f91
Compare
Before processing the directory, if it ends with "." or "..", it now immediately returns with the same error message as GNU
Should close #6620