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

Prevent file handle leak during individual purge #707

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,8 @@ Set<Path> getDerivativeImageFiles(Identifier identifier)
hashedPathFragment(identifier.toString()));
final String expectedNamePrefix =
StringUtils.md5(identifier.toString());
try {
return Files.list(cachePath)
try (final var fileStream = Files.list(cachePath)) {
return fileStream
.filter(p -> p.getFileName().toString().startsWith(expectedNamePrefix))
Copy link
Contributor

Choose a reason for hiding this comment

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

@bbpennel. Nice! so the try() will auto close the fileStream... But... is the filter needed? Given the way caches are structured all files inside cachePath will need to be returned. Maybe for sanity just check if the file is regular file?
.filter(Files::isRegularFile) or something like that? I mean, just to save a few milliseconds per cycle... specially on large images with tons of derivatives

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The filter isn't a change in this PR, i didn't really evaluate whether it was needed or not. I'm fine with removing it if there isn't any concern of the cache path containing files that don't begin with the md5.

Copy link
Contributor

Choose a reason for hiding this comment

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

@bbpennel thanks, true!, for the sake of not adding any point of rupture and because I don't know what use case the original Developer might had had in place, let's keep it! Approving. Thanks!

.collect(Collectors.toUnmodifiableSet());
} catch (NoSuchFileException e) {
Expand Down