-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Use File.list and File.walk within a try with resource #5718
Conversation
The API contract of File.list and File.walk requires them to be closed after use.
Left out filter
Factored out deleteFile with better debug
try | ||
{ | ||
sweepFile(now, p); | ||
if (!Files.deleteIfExists(p)) |
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.
Bzzzt. Do not pass go, do not collect $100. YOu can only delete it if it has expired!
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.
oooops fixed
LOG.warn(e); | ||
if (!Files.deleteIfExists(p)) | ||
LOG.warn("Could not delete {}", p.getFileName()); | ||
if (LOG.isDebugEnabled()) |
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.
So the debug output looking like the delete happened will be done even if the file wasn't actually deleted.
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.
factored out to a better common deleteFile method
try | ||
{ | ||
sweepFile(now, p); | ||
if (!Files.deleteIfExists(p)) | ||
LOG.warn("Could not delete {}", p.getFileName()); |
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.
In general, I'm not sure we need to do the delete outside of the stream: there are plenty of examples if you do a google search where the recommended way to do a recursive directory delete is to use Files.walk/list and delete each file. I can't find any counter examples that says that is a bad idea.
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.
OK I have switched back.
jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionDataStore.java
Show resolved
Hide resolved
Can delete files whilst walking
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'm good with this.
The session specific behaviors that @janbartel pointed out seem important though.
} | ||
catch (Exception e) | ||
{ | ||
LOG.warn(e); | ||
} | ||
} | ||
|
||
public boolean isExpired(long now, Path p) |
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 see the benefit of splitting sweepFile() into isExpired() and then deleteFile() - it's more efficient just to use sweepFile().
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.
Ah now that we no longer collect before delete, there is none....
Restored sweepFile fixed minor code suggestions
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.
LGTM
The API contract of File.list and File.walk requires them to be closed after use.