Skip to content

Commit e298ba5

Browse files
committed
simplify dbus-send check
1 parent 4b81bff commit e298ba5

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

src/main/java/org/cryptomator/linux/revealpath/DBusSendRevealPathService.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import java.nio.file.Path;
1212
import java.nio.file.attribute.BasicFileAttributes;
1313
import java.util.Arrays;
14-
import java.util.concurrent.CountDownLatch;
1514
import java.util.concurrent.TimeUnit;
1615
import java.util.stream.Collectors;
1716

@@ -60,20 +59,10 @@ public void reveal(Path path) throws RevealFailedException {
6059

6160
@Override
6261
public boolean isSupported() {
63-
CountDownLatch waitBarrier = new CountDownLatch(2);
64-
ProcessBuilder dbusSendExistsBuilder = new ProcessBuilder().command("test", " `command -v dbus-send`");
65-
ProcessBuilder fileManager1ExistsBuilder = createFileManager1Check();
66-
6762
try {
68-
var dbusSendExists = dbusSendExistsBuilder.start();
69-
dbusSendExists.onExit().thenRun(waitBarrier::countDown);
70-
var fileManager1Exists = fileManager1ExistsBuilder.start();
71-
fileManager1Exists.onExit().thenRun(waitBarrier::countDown);
72-
73-
if (waitBarrier.await(TIMEOUT_THRESHOLD, TimeUnit.MILLISECONDS)) {
74-
if (dbusSendExists.exitValue() == 0 && fileManager1Exists.exitValue() == 0) {
75-
return parseOutputForFileManagerInterface(fileManager1Exists);
76-
}
63+
var fileManager1Exists = createFileManager1Check().start();
64+
if (fileManager1Exists.waitFor(TIMEOUT_THRESHOLD, TimeUnit.MILLISECONDS) && fileManager1Exists.exitValue() == 0) {
65+
return parseOutputForFileManagerInterface(fileManager1Exists);
7766
}
7867
} catch (IOException | InterruptedException e) {
7968
//NO-OP
@@ -90,7 +79,7 @@ public boolean isSupported() {
9079
* @throws IOException if the Inputer reader on the process output cannot be created
9180
*/
9281
private boolean parseOutputForFileManagerInterface(Process fileManager1Process) throws IOException {
93-
if( fileManager1Process.isAlive()) {
82+
if (fileManager1Process.isAlive()) {
9483
throw new IllegalArgumentException("Process " + fileManager1Process + " must be terminated to read output.");
9584
}
9685
try (var reader = fileManager1Process.inputReader(StandardCharsets.UTF_8)) {

0 commit comments

Comments
 (0)