-
Notifications
You must be signed in to change notification settings - Fork 72
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
fix: don't error on deleting shared folder for scripts #1138
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #1138 +/- ##
=========================================
Coverage 30.41% 30.41%
- Complexity 14850 14856 +6
=========================================
Files 1037 1037
Lines 161464 161469 +5
Branches 35194 35195 +1
=========================================
+ Hits 49106 49113 +7
Misses 103485 103485
+ Partials 8873 8871 -2
Continue to review full report at Codecov.
|
public static boolean isEmptyDirectory(Path path) throws IOException { | ||
if (!Files.isDirectory(path)) return false; | ||
|
||
var listFiles = Files.list(path); |
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.
Not certain of the syntax but I believe you. Any particular benefit to this instead of checking the length of Files.list(path)? I do note that Files.list() won't return the dot or dot dot references which is the only weird case I can think of. Obviously not blocking.
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.
Files.list
returns a stream. Checking whether the stream has any values is faster than checking whether the length of the list is 0, because checking the length will enumerate every item in the list, which /could/ be slow (e.g. on HDD, or if a script somehow has hundreds or thousands of files).
Probably the issue on loathers/ChIT#24.
Suppose we have two scripts, both of which store something in the folder
images/relayimages
. Then deleting one script would fail, because the folder will fail to be deleted (as it's non-empty).Check for a non-empty folder, and don't delete the folder in that case.