From b1a3ef9023de69131e4e9bbe1444a30cf72a8973 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Tue, 23 May 2023 12:35:14 +0200 Subject: [PATCH] prevent dealing with unclosed directory streams --- .../DropboxLinuxLocationPresetsProvider.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/cryptomator/common/locationpresets/DropboxLinuxLocationPresetsProvider.java b/src/main/java/org/cryptomator/common/locationpresets/DropboxLinuxLocationPresetsProvider.java index 32d673da4..ce159a019 100644 --- a/src/main/java/org/cryptomator/common/locationpresets/DropboxLinuxLocationPresetsProvider.java +++ b/src/main/java/org/cryptomator/common/locationpresets/DropboxLinuxLocationPresetsProvider.java @@ -3,12 +3,12 @@ package org.cryptomator.common.locationpresets; import org.cryptomator.integrations.common.OperatingSystem; import java.io.IOException; +import java.io.UncheckedIOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.function.Predicate; import java.util.regex.Pattern; import java.util.stream.Stream; -import java.util.stream.StreamSupport; import static org.cryptomator.integrations.common.OperatingSystem.Value.LINUX; @@ -20,11 +20,12 @@ public final class DropboxLinuxLocationPresetsProvider implements LocationPreset @Override public Stream getLocations() { - try (var dirStream = Files.newDirectoryStream(USER_HOME, "Dropbox*")) { - return StreamSupport.stream(dirStream.spliterator(), false) // - .filter(p -> Files.isDirectory(p) && PATTERN.test(p.getFileName().toString())) // - .map(p -> new LocationPreset(p.getFileName().toString(), p)); - } catch (IOException e) { + try (var dirStream = Files.list(USER_HOME)) { + var presets = dirStream.filter(p -> Files.isDirectory(p) && PATTERN.test(p.getFileName().toString())) // + .map(p -> new LocationPreset(p.getFileName().toString(), p)) // + .toList(); + return presets.stream(); //workaround to ensure that the directory stream is always closed + } catch (IOException | UncheckedIOException e) { //UncheckedIOException thrown by the stream of Files.list() return Stream.of(); } }