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

[Improvement] [Issue 9200] Add recursive argument to removeDir procedure #9215

Closed
wants to merge 7 commits into from
Closed

[Improvement] [Issue 9200] Add recursive argument to removeDir procedure #9215

wants to merge 7 commits into from

Conversation

chrisokuda
Copy link
Contributor

@chrisokuda chrisokuda commented Oct 5, 2018

This PR adds additional functionality as requested in #9200, but does not fix #9200.

This PR adds a recursive boolean argument to removeDir. If recursive is true (default) then the behavior is exactly as before. If it is false, then we check to ensure the path provided is truly an empty directory (i.e.: not a file).

Chris McIntyre added 3 commits October 5, 2018 14:21
@chrisokuda chrisokuda changed the title Issue 9200 improve remove dir [Improvement] [Issue 9200] Add recursive argument to removeDir procedure Oct 5, 2018
@chrisokuda
Copy link
Contributor Author

This does not yet have tests. If desired, I'll need some assistance writing one.

Copy link
Collaborator

@alaviss alaviss left a comment

Choose a reason for hiding this comment

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

As for tests, you should add something like this to this line, then adjust the output at the beginning of the file. You can run the test locally with

./koch tests r stdlib/tos

To check if your modification worked.

lib/pure/os.nim Outdated Show resolved Hide resolved
lib/pure/os.nim Outdated Show resolved Hide resolved
- 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.
@chrisokuda
Copy link
Contributor Author

I have added a new commit to (1) remove the unnecessary else: block code and (2) add 2 tests to ensure the non-recursive mode works (It does; I tested locally). Thanks so much to @alaviss for helping me out; I am excited to continue contributing.

lib/pure/os.nim Outdated Show resolved Hide resolved
@chrisokuda
Copy link
Contributor Author

Fixed and simplified the doc comment, thanks to feedback from @alaviss.

Copy link
Collaborator

@alaviss alaviss left a comment

Choose a reason for hiding this comment

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

Some small suggestions.

tests/stdlib/tos.nim Outdated Show resolved Hide resolved
lib/pure/os.nim Outdated Show resolved Hide resolved
lib/pure/os.nim Outdated Show resolved Hide resolved
os.nim: Don't need to specify default behavior, it's clear.
@Araq
Copy link
Member

Araq commented Oct 9, 2018

I fail to see the point. When do I not want to remove a directory plus its contents?

@chrisokuda
Copy link
Contributor Author

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 rm and the vast majority of other programming languages I can think of.

@Araq
Copy link
Member

Araq commented Oct 9, 2018

Yeah but they are all wrong.

@chrisokuda
Copy link
Contributor Author

@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.

@Araq
Copy link
Member

Araq commented Oct 9, 2018

Alright then, thanks. :-)

@Araq Araq closed this Oct 9, 2018
@chrisokuda chrisokuda deleted the issue-9200-improve-removeDir branch October 9, 2018 20:56
@jibal
Copy link

jibal commented Jun 11, 2020

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.

@chrisokuda
Copy link
Contributor Author

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!

@Araq
Copy link
Member

Araq commented Jun 12, 2020

It's only dangerous because Unix never got fixed to offer an undo mechanism.

@jibal
Copy link

jibal commented Jun 12, 2020 via email

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.

[os] removeFile(path) also removes directories ; not documented
4 participants