Skip to content
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

Fixed #1769: rm: -d should match GNU's output #1780

Closed
wants to merge 10 commits into from

Conversation

billyb2
Copy link

@billyb2 billyb2 commented Mar 9, 2021

Using some code from @growse 's pull request, I made a quick match statement that checks if the error is the Directory not found error. If so, it uses the show_custom_error_description macro to output said error, just without the "(os error)" part.

billyb2 added a commit to billyb2/coreutils that referenced this pull request Mar 9, 2021
I noticed that the verbose option was not implemented at all for rm -rf -v, so I added a quick if statement to fix it. This commit would also fix uutils#1769, as it's one commit ahead of uutils#1780
billyb2 added a commit to billyb2/coreutils that referenced this pull request Mar 9, 2021
I noticed that the verbose option was not implemented at all for rm -rf -v, so I added a quick if statement to fix it. This commit would also fix uutils#1769, as it's one commit ahead of uutils#1780
@billyb2
Copy link
Author

billyb2 commented Mar 9, 2021

All the extra commits are rebases.

@billyb2
Copy link
Author

billyb2 commented Mar 9, 2021

Added the test that you wanted

billyb2 added 6 commits March 9, 2021 18:35
Using some code from @growse 's pull request, I made a quick match statement that checks if the error is the Directory not found error. If so, it uses the show_custom_error_description macro to output said error, just without the "(os error)" part.
I didn't realize that changing the Cargo.lock would make builds on some
platforms fail, so I reverted it back
Just another test in the test_rm_errors fn that runs rm -d on the same
dir as the previous test
my PC is very low on space, so Im kind of pushing commits blindly
The output should have been cannot remove, instead of removing. That was a mistake on my end.
There were some minor formatting issues with how the test_rm.rs file
looked (I wrote the code on my phone, jaja) so I tidied it up.
@billyb2
Copy link
Author

billyb2 commented Mar 9, 2021

Yea that's my bad, I wrote the code on my phone. The formatting should be good now.

billyb2 added 3 commits March 9, 2021 19:40
Apparently, I will different platforms have different error codes for a
directory being full, so I instead check if the error message starts
with "Directory not found"
Windows gives a different error message then Unix based OS, so I added
some Windows specific code
MinRustV fails if the lock file isnt built for Rust 1.33.0, so I ran
cargo +1.33.0 update like it asked
@@ -306,7 +307,15 @@ fn remove_dir(path: &Path, options: &Options) -> bool {
}
}
Err(e) => {
show_error!("removing '{}': {}", path.display(), e);
if e.to_string().starts_with("Directory not empty") || (cfg!(windows) && e.to_string().starts_with("The directory is not empty")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can rely on the error message itself; it might change in rustc itself
there is no stable error code here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried looking, and I honestly can't find one. Do you have any ideas? I thought that the raw error code would work, but it's different across Windows, Linux, etc. The two error messages given should work for all Unix based operating systems, and Windows is its own beast.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also does pass all of the tests, and any non Unix-based OS would be difficult to plan for, since there error codes could be anything at all.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what to do here tbh :/
@Arcterus @rivy any idea/suggestion ? :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Unix, it’s probably best to check errno for ENOTEMPTY/EEXIST (you can use either nix or libc directly). I’m not exactly sure how to check the windows error code, but there’s likely a function in winapi (or the new crate made by Microsoft itself?).

Copy link
Contributor

@sylvestre sylvestre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

waiting if we can find a better solution

@billyb2
Copy link
Author

billyb2 commented Mar 13, 2021

@syvlestre that's totally fine

@sylvestre
Copy link
Contributor

I am not a huge fan for this PR. I think it adds unnecessary complexity. Sorry :(

@sylvestre sylvestre closed this Apr 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants