-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[Improvement] [Issue 9200] Add recursive
argument to removeDir
procedure
#9215
[Improvement] [Issue 9200] Add recursive
argument to removeDir
procedure
#9215
Conversation
…Dir` will now check that the path `dir` is not a file and is empty if `recursive == false`.
recursive
argument to removeDir
procedure
This does not yet have tests. If desired, I'll need some assistance writing one. |
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.
- Removed the `bool` type description. - Removed all of the `else` block, because it is not needed since `rawRemoveDir` will not delete a non-empty directory or a file. tos.nim: - Added 2 tests to ensure non-empty directories (1) and files (2) will not be deleted in non-recursive mode.
I have added a new commit to (1) remove the unnecessary |
Fixed and simplified the doc comment, thanks to feedback from @alaviss. |
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.
Some small suggestions.
os.nim: Don't need to specify default behavior, it's clear.
I fail to see the point. When do I not want to remove a directory plus its contents? |
The originator of #9200 requested this as a feature. I personally think non-recursive directory removal should be the default (obviously a breaking change we could discuss later), as it is with |
Yeah but they are all wrong. |
@Araq Haha, I cannot argue with that. Feel free to close this if you want, I was just practicing a bit and dipping in my toes. I did learn a lot with this exercise. |
Alright then, thanks. :-) |
It's unfortunate that this was closed. Removing an empty directory is safe and can undone. Removing a directory that isn't empty is dangerous and cannot be undone. An incorrect path to removeDir, either through user error or a program bug, can spell disaster. |
I agree, but I'm not using nim any longer. The fix was really easy, I am sure, because I didn't know much about nim at the time. Good luck! |
It's only dangerous because Unix never got fixed to offer an undo mechanism. |
It's dangerous because it's obviously dangerous (everywhere, not just UNIX ... and FWIW, I'm developing on Windows). And as long as it's
dangerous, for whatever reason, there ought to be a way to remove a
directory only if it's empty. And even if it weren't dangerous, it's still useful to remove empty directories that get left around. Everyone else is right about this.
…On Fri, Jun 12, 2020 at 1:45 AM Andreas Rumpf ***@***.***> wrote:
It's only dangerous because Unix never got fixed to offer an undo
mechanism.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#9215 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEDT2C6AULBXYSCWI3XISDRWHTK3ANCNFSM4FZL46YQ>
.
|
This PR adds additional functionality as requested in #9200, but does not fix #9200.
This PR adds a
recursive
boolean argument toremoveDir
. Ifrecursive
istrue
(default) then the behavior is exactly as before. If it isfalse
, then we check to ensure the path provided is truly an empty directory (i.e.: not a file).