-
Notifications
You must be signed in to change notification settings - Fork 122
88: Add nob_delete_dir #103
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: James Orson <jamesaorson@gmail.com>
btw nob_delete_file can delete a dir if it is empty ( same as rmdir). |
It isn't, but it's deprecated. (link) |
Signed-off-by: James Orson <jamesaorson@gmail.com>
Also can you async your branch for the updated main? The Version is 1.22.o in your branch |
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.
As a general note, I don't like that we use nob_read_entire_dir()
for this. nob_read_entire_dir()
reads entire dir upfront, but what if the dir contains huge amount of files? We should iterate them incrementally. But unfortunately, we don't have an incremental "walker" through the files of a dir yet.
We may go with the current approach for now, implement the incremental walker later, and then reimplement nob_delete_dir()
with it.
nob.h
Outdated
Nob_File_Paths children = {0}; | ||
if (!nob_read_entire_dir(path, &children)) return false; | ||
|
||
Nob_Log_Level old_log_level = nob_minimal_log_level; |
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.
I don't think it should be the responsibility of this function to control the log level.
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.
Agreed, but do we want to print out a message for every file we encounter?
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 for now, but the tests demonstrate the noisiness I am talking about:
$ cc ./tests/delete_dir.c -I. && ./a.out
[INFO] created directory `delete_dir`
[INFO] created directory `delete_dir/nested`
[INFO] deleting delete_dir
[INFO] deleting delete_dir/baz.txt
[INFO] deleting delete_dir/bar.txt
[INFO] deleting delete_dir/nested
[INFO] deleting delete_dir/nested/baz.txt
[INFO] deleting delete_dir/nested/foo.txt
[INFO] deleting delete_dir/nested/bar.txt
[INFO] deleting delete_dir/nested
[INFO] deleting delete_dir
[INFO] created directory `delete_dir`
[INFO] created directory `delete_dir/nested`
[INFO] deleting delete_dir
[INFO] deleting delete_dir/baz.txt
[INFO] deleting delete_dir/bar.txt
[INFO] deleting delete_dir/nested
[INFO] deleting delete_dir/nested/baz.txt
[INFO] deleting delete_dir/nested/foo.txt
[INFO] deleting delete_dir/nested/link
[INFO] deleting delete_dir/nested/bar.txt
[INFO] deleting delete_dir/nested
[INFO] deleting delete_dir
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.
Be nice to have optional parameters to provide function-scoped log level overrides.
Signed-off-by: James Orson <jamesaorson@gmail.com>
Signed-off-by: James Orson <jamesaorson@gmail.com>
Closes #88