Skip to content

Commit 9c54a3d

Browse files
committed
fix: Files.list is not in a try-with-resources block
1 parent 3cac768 commit 9c54a3d

2 files changed

Lines changed: 23 additions & 20 deletions

File tree

stackgres-k8s/src/common/src/main/java/io/stackgres/common/extension/ExtensionManager.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -198,19 +198,21 @@ public void installExtension() throws Exception {
198198
}
199199

200200
public void createExtensionLinks() throws Exception {
201-
fileSystemHandler
202-
.list(Paths.get(ClusterPath.PG_EXTENSIONS_LIB_PATH.path(context)))
203-
.map(libFile -> Tuple.tuple(libFile,
204-
Paths.get(ClusterPath.PG_RELOCATED_LIB_PATH.path(context))
205-
.resolve(libFile.getFileName())))
206-
.forEach(
207-
Unchecked.consumer(t -> {
208-
Path targetParent = t.v2.getParent();
209-
if (targetParent != null) {
210-
fileSystemHandler.createDirectories(targetParent);
211-
}
212-
fileSystemHandler.createOrReplaceSymbolicLink(t.v2, t.v1);
213-
}));
201+
try (var list = fileSystemHandler
202+
.list(Paths.get(ClusterPath.PG_EXTENSIONS_LIB_PATH.path(context)))) {
203+
list
204+
.map(libFile -> Tuple.tuple(libFile,
205+
Paths.get(ClusterPath.PG_RELOCATED_LIB_PATH.path(context))
206+
.resolve(libFile.getFileName())))
207+
.forEach(
208+
Unchecked.consumer(t -> {
209+
Path targetParent = t.v2.getParent();
210+
if (targetParent != null) {
211+
fileSystemHandler.createDirectories(targetParent);
212+
}
213+
fileSystemHandler.createOrReplaceSymbolicLink(t.v2, t.v1);
214+
}));
215+
}
214216
fileSystemHandler.createOrReplaceFile(
215217
Paths.get(ClusterPath.PG_RELOCATED_LIB_PATH.path(context))
216218
.resolve(packageName + LINKS_CREATED_SUFFIX));

stackgres-k8s/src/common/src/main/java/io/stackgres/common/patroni/PatroniCtlBinaryInstance.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,14 @@ final String patroniCtlCommand(String version) {
132132
patroniMajorVersion = 3;
133133
}
134134
final String patroniVersionPrefix = PATRONICTL_BINARY_PREFIX_PATH + patroniMajorVersion + ".";
135-
var pathFound = Unchecked.supplier(() -> Files.list(Paths.get(BIN_PATH)))
136-
.get()
137-
.filter(path -> path.getFileName().toString().startsWith(patroniVersionPrefix))
138-
.sorted(new PatroniCtlPathComparator().reversed())
139-
.findFirst();
140-
if (pathFound.isPresent()) {
141-
return pathFound.get().toAbsolutePath().toString();
135+
try (var list = Unchecked.supplier(() -> Files.list(Paths.get(BIN_PATH))).get()) {
136+
var pathFound = list
137+
.filter(path -> path.getFileName().toString().startsWith(patroniVersionPrefix))
138+
.sorted(new PatroniCtlPathComparator().reversed())
139+
.findFirst();
140+
if (pathFound.isPresent()) {
141+
return pathFound.get().toAbsolutePath().toString();
142+
}
142143
}
143144
throw new RuntimeException("No patronictl binary found for version " + version);
144145
}

0 commit comments

Comments
 (0)