Skip to content

Commit

Permalink
simplify dbus-send check
Browse files Browse the repository at this point in the history
  • Loading branch information
infeo committed Aug 16, 2024
1 parent 4b81bff commit e298ba5
Showing 1 changed file with 4 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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)) {
Expand Down

0 comments on commit e298ba5

Please sign in to comment.