From e298ba59068ab7215f55cfab821f05b6198a32c1 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Fri, 16 Aug 2024 10:20:29 +0200 Subject: [PATCH] simplify dbus-send check --- .../revealpath/DBusSendRevealPathService.java | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/cryptomator/linux/revealpath/DBusSendRevealPathService.java b/src/main/java/org/cryptomator/linux/revealpath/DBusSendRevealPathService.java index 39529ff..be39d6b 100644 --- a/src/main/java/org/cryptomator/linux/revealpath/DBusSendRevealPathService.java +++ b/src/main/java/org/cryptomator/linux/revealpath/DBusSendRevealPathService.java @@ -11,7 +11,6 @@ import java.nio.file.Path; import java.nio.file.attribute.BasicFileAttributes; import java.util.Arrays; -import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -60,20 +59,10 @@ public void reveal(Path path) throws RevealFailedException { @Override public boolean isSupported() { - CountDownLatch waitBarrier = new CountDownLatch(2); - ProcessBuilder dbusSendExistsBuilder = new ProcessBuilder().command("test", " `command -v dbus-send`"); - ProcessBuilder fileManager1ExistsBuilder = createFileManager1Check(); - try { - var dbusSendExists = dbusSendExistsBuilder.start(); - dbusSendExists.onExit().thenRun(waitBarrier::countDown); - var fileManager1Exists = fileManager1ExistsBuilder.start(); - fileManager1Exists.onExit().thenRun(waitBarrier::countDown); - - if (waitBarrier.await(TIMEOUT_THRESHOLD, TimeUnit.MILLISECONDS)) { - if (dbusSendExists.exitValue() == 0 && fileManager1Exists.exitValue() == 0) { - return parseOutputForFileManagerInterface(fileManager1Exists); - } + var fileManager1Exists = createFileManager1Check().start(); + if (fileManager1Exists.waitFor(TIMEOUT_THRESHOLD, TimeUnit.MILLISECONDS) && fileManager1Exists.exitValue() == 0) { + return parseOutputForFileManagerInterface(fileManager1Exists); } } catch (IOException | InterruptedException e) { //NO-OP @@ -90,7 +79,7 @@ public boolean isSupported() { * @throws IOException if the Inputer reader on the process output cannot be created */ private boolean parseOutputForFileManagerInterface(Process fileManager1Process) throws IOException { - if( fileManager1Process.isAlive()) { + if (fileManager1Process.isAlive()) { throw new IllegalArgumentException("Process " + fileManager1Process + " must be terminated to read output."); } try (var reader = fileManager1Process.inputReader(StandardCharsets.UTF_8)) {