diff options
author | Martin Polden <mpolden@mpolden.no> | 2022-06-08 16:09:02 +0200 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2022-06-13 10:47:53 +0200 |
commit | 49c0276d5286f469b02f774360fbe8d964cd7556 (patch) | |
tree | 9850a9d5a2d55a1e31aad2e22570435618087513 /routing-generator | |
parent | c43c9d5e9e9f5fe459cae5c255d04be1ad4eb8c1 (diff) |
Close directory stream
Diffstat (limited to 'routing-generator')
-rw-r--r-- | routing-generator/src/main/java/com/yahoo/vespa/hosted/routing/nginx/Nginx.java | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/routing-generator/src/main/java/com/yahoo/vespa/hosted/routing/nginx/Nginx.java b/routing-generator/src/main/java/com/yahoo/vespa/hosted/routing/nginx/Nginx.java index 1f5324223be..b197bff7a51 100644 --- a/routing-generator/src/main/java/com/yahoo/vespa/hosted/routing/nginx/Nginx.java +++ b/routing-generator/src/main/java/com/yahoo/vespa/hosted/routing/nginx/Nginx.java @@ -115,12 +115,13 @@ public class Nginx implements Router { Instant oneWeekAgo = clock.instant().minus(Duration.ofDays(7)); // Rotated files have the format <basename>-yyyy-MM-dd-HH:mm:ss.SSS String configBasename = NginxPath.config.in(fileSystem).getFileName().toString(); - Files.list(NginxPath.root.in(fileSystem)) - .filter(Files::isRegularFile) - .filter(path -> path.getFileName().toString().startsWith(configBasename)) - .filter(path -> rotatedAt(path).map(instant -> instant.isBefore(oneWeekAgo)) - .orElse(false)) - .forEach(path -> Exceptions.uncheck(() -> Files.deleteIfExists(path))); + try (var entries = Files.list(NginxPath.root.in(fileSystem))) { + entries.filter(Files::isRegularFile) + .filter(path -> path.getFileName().toString().startsWith(configBasename)) + .filter(path -> rotatedAt(path).map(instant -> instant.isBefore(oneWeekAgo)) + .orElse(false)) + .forEach(path -> Exceptions.uncheck(() -> Files.deleteIfExists(path))); + } } /** Returns the time given path was rotated */ |