-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
Don't fail os.remove(file)
when the file doesn't exist
#86
Conversation
This is what the docs say, and what `os.remove.all` does, but with a single file it may throw `FileNotFoundException`
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.
According the the Documentation (readme.md
) this behavior is correct.
A more appropriate fix is to correct the ScalaDoc.
Could you point to the part of the README that says the file must exist? I checked again, and it only says that when removing a directory it needs to be empty, and otherwise use Given that |
You're right, this is not stated explicitly in the documentation. But it's mirroring the behavior of Java File API as well as Unix
You can check for existence before you delete. After your proposed change, many other use cases may no longer work. E.g. you'll no longer see an error when a file, you expect to exist, doesn't. I'm not arguing which API is better, but I think we are already consistent with what users expect. Looks like what you really want is to mimic/add the |
I'll stop after this comment, but my reasoning is as follows:
If there are some rare use cases where you'd need to know if the file you tried to delete, there could be a return value form |
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.
These are very convincing points. I agree, your proposal is very in the aim of usability. This is still a behavior-breaking change, so let's give others the chance to speak, whether they see any issue in this change. Thanks for your persistence.
I changed my mind, lots of valid arguments were presented
I'm personally neutral:
Maybe we can merge this, and add an override to keep the old behavior around? Like |
If we're going to do this, we should also consider changing the return type from @lefou what do you think? |
I'd also go with |
Sounds good, and thank you for your flexibility, @lefou! I'll try to make the changes tomorrow. |
I initially also liked the addition parameter, but found it hard to decide between $ rm --help
Usage: rm [OPTION]... [FILE]...
Remove (unlink) the FILE(s).
-f, --force ignore nonexistent files and arguments, never prompt
... I still struggle with the default value though. To really make programmers life easier, we should make the not-fail version the default, but that will semantically collide with the binary compatibility override, which I think we should provide in any case. For completeness, we also have the option to add yet another named entry point |
|
Yeah I'm willing to break binary compatibility here. We are already breaking bincompat in recent changes to Fansi and PPrint and Mill, and will need to do a coordinated release of the libraries anyway, so might as well include OS-Lib in that group. It's a tradeoff maintaining bincompat and maintaining a nice API, and since we have an opportunity to break compat presents itself we should take it. In that case, I think the thing to do would be:
|
Sound reasonable. Though, I don't think the way other projects handle their compatibility stories should hinder us doing the right thing. Changing bin-compat is no big issue, as long as we increasing the version properly. |
… flag to fall back to old behavior #89 Follow up from the discussion in #86. As discussed, we hope that it would be more intuitive to avoid failing loudly if a file we want to delete already doesn't exist. If the user cares, they can always check the returned `Boolean`, or pass `checkExists = true` if they want the exception CC @iulian-db Review by @lefou @sake92
Superseded by #89 I think |
This is what the docs say, and what
os.remove.all
does, but with a single file it may throwFileNotFoundException