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

fix: don't error on deleting shared folder for scripts #1138

Merged
merged 3 commits into from
Oct 1, 2022

Conversation

midgleyc
Copy link
Member

@midgleyc midgleyc commented Oct 1, 2022

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.

@midgleyc midgleyc requested a review from a team as a code owner October 1, 2022 16:42
@codecov
Copy link

codecov bot commented Oct 1, 2022

Codecov Report

Merging #1138 (1e28f33) into main (827175d) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
...t/sourceforge/kolmafia/scripts/git/GitManager.java 54.24% <100.00%> (+0.44%) ⬆️
.../sourceforge/kolmafia/utilities/FileUtilities.java 42.91% <100.00%> (+0.91%) ⬆️
...et/sourceforge/kolmafia/scripts/ScriptManager.java 62.74% <0.00%> (+1.96%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 827175d...1e28f33. Read the comment docs.

public static boolean isEmptyDirectory(Path path) throws IOException {
if (!Files.isDirectory(path)) return false;

var listFiles = Files.list(path);
Copy link
Contributor

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.

Copy link
Member Author

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

@midgleyc midgleyc merged commit 838752b into kolmafia:main Oct 1, 2022
@midgleyc midgleyc deleted the git-shared-folder branch October 1, 2022 21:44
@midgleyc midgleyc added the git-scripts Install scripts using git label Oct 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
git-scripts Install scripts using git
Projects
None yet
2 participants