Skip to content

Commit e2c7ff0

Browse files
committed
Merge branch 'develop' into release/1.2.0
2 parents cc65fd9 + 447782d commit e2c7ff0

File tree

3 files changed

+51
-19
lines changed

3 files changed

+51
-19
lines changed

src/main/java/org/cryptomator/linux/revealpath/DBusFileMangerRevealPath.java renamed to src/main/java/org/cryptomator/linux/revealpath/DBusSendRevealPathService.java

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.cryptomator.linux.revealpath;
22

3+
import com.google.common.base.Preconditions;
34
import org.cryptomator.integrations.revealpath.RevealFailedException;
45
import org.cryptomator.integrations.revealpath.RevealPathService;
56

@@ -15,8 +16,12 @@
1516
import java.util.concurrent.TimeUnit;
1617
import java.util.stream.Collectors;
1718

18-
public class DBusFileMangerRevealPath implements RevealPathService {
19+
/**
20+
* RevealPathService provider using the <a href="https://freedesktop.org/wiki/Specifications/file-manager-interface/">DBus freedesktop FileManager1 interface</a> and dbus-send command.
21+
*/
22+
public class DBusSendRevealPathService implements RevealPathService {
1923

24+
private static final String FILEMANAGER1_XML_ELEMENT = "<interface name=\"org.freedesktop.FileManager1\">";
2025
private static final String FOR_FOLDERS = "org.freedesktop.FileManager1.ShowFolders";
2126
private static final String FOR_FILES = "org.freedesktop.FileManager1.ShowItems";
2227
private static final int TIMEOUT_THRESHOLD = 5000;
@@ -56,24 +61,52 @@ public void reveal(Path path) throws RevealFailedException {
5661

5762
@Override
5863
public boolean isSupported() {
59-
CountDownLatch waitBarrier = new CountDownLatch(3);
60-
ProcessBuilder builderExistsDbusSend = new ProcessBuilder().command("which", "dbus-send");
61-
ProcessBuilder builderExistsNautilus = new ProcessBuilder().command("which", "nautilus");
62-
ProcessBuilder builderExistsDolphin = new ProcessBuilder().command("which", "dolphin");
64+
CountDownLatch waitBarrier = new CountDownLatch(2);
65+
ProcessBuilder dbusSendExistsBuilder = new ProcessBuilder().command("test", " `command -v dbus-send`");
66+
ProcessBuilder fileManager1ExistsBuilder = createFileManager1Check();
67+
6368
try {
64-
var existsDbusSend = builderExistsDbusSend.start();
65-
existsDbusSend.onExit().thenRun(waitBarrier::countDown);
66-
var existsNautilus = builderExistsNautilus.start();
67-
existsNautilus.onExit().thenRun(waitBarrier::countDown);
68-
var existsDolphin = builderExistsDolphin.start();
69-
existsDolphin.onExit().thenRun(waitBarrier::countDown);
69+
var dbusSendExists = dbusSendExistsBuilder.start();
70+
dbusSendExists.onExit().thenRun(waitBarrier::countDown);
71+
var fileManager1Exists = fileManager1ExistsBuilder.start();
72+
fileManager1Exists.onExit().thenRun(waitBarrier::countDown);
73+
7074
if (waitBarrier.await(TIMEOUT_THRESHOLD, TimeUnit.MILLISECONDS)) {
71-
return existsDbusSend.exitValue() == 0 && (existsNautilus.exitValue() == 0 | existsDolphin.exitValue() == 0);
75+
if (dbusSendExists.exitValue() == 0 && fileManager1Exists.exitValue() == 0) {
76+
return parseOutputForFileManagerInterface(fileManager1Exists);
77+
}
7278
}
7379
} catch (IOException | InterruptedException e) {
7480
//NO-OP
7581
}
7682
return false;
7783
}
7884

85+
/**
86+
* Parses process stdout to see if the answer contains "{@value FILEMANAGER1_XML_ELEMENT}".
87+
* DBus introspection output is defined in the <a href="https://dbus.freedesktop.org/doc/dbus-specification.html#introspection-format">dbus spec</a>.
88+
*
89+
* @param fileManager1Process The already exited process for checking the FileManager1 interface
90+
* @return {@code true} if the interface is found in the introspection output, otherwise false
91+
* @throws IOException if the Inputer reader on the process output cannot be created
92+
*/
93+
private boolean parseOutputForFileManagerInterface(Process fileManager1Process) throws IOException {
94+
Preconditions.checkState(!fileManager1Process.isAlive());
95+
try (var reader = fileManager1Process.inputReader(StandardCharsets.UTF_8)) {
96+
return reader.lines().map(String::trim).anyMatch(FILEMANAGER1_XML_ELEMENT::equals);
97+
}
98+
}
99+
100+
private static ProcessBuilder createFileManager1Check() {
101+
return new ProcessBuilder().command(
102+
"dbus-send",
103+
"--session",
104+
"--print-reply",
105+
"--reply-timeout=" + TIMEOUT_THRESHOLD,
106+
"--dest=org.freedesktop.FileManager1",
107+
"--type=method_call",
108+
"/org/freedesktop/FileManager1",
109+
"org.freedesktop.DBus.Introspectable.Introspect"
110+
);
111+
}
79112
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
org.cryptomator.linux.revealpath.DBusFileMangerRevealPath
1+
org.cryptomator.linux.revealpath.DBusSendRevealPathService

src/test/java/org/cryptomator/linux/keychain/DbusFileManagerRevealPathTest.java renamed to src/test/java/org/cryptomator/linux/revealpath/DBusSendRevealPathServiceTest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
package org.cryptomator.linux.keychain;
1+
package org.cryptomator.linux.revealpath;
22

33
import org.cryptomator.integrations.revealpath.RevealFailedException;
4-
import org.cryptomator.linux.revealpath.DBusFileMangerRevealPath;
54
import org.junit.jupiter.api.Assertions;
65
import org.junit.jupiter.api.Assumptions;
76
import org.junit.jupiter.api.Disabled;
@@ -14,10 +13,10 @@
1413

1514
@EnabledOnOs(OS.LINUX)
1615
@Disabled
17-
public class DbusFileManagerRevealPathTest {
16+
public class DBusSendRevealPathServiceTest {
1817

1918
@TempDir Path tmpDir;
20-
DBusFileMangerRevealPath inTest = new DBusFileMangerRevealPath();
19+
DBusSendRevealPathService inTest = new DBusSendRevealPathService();
2120

2221
@Test
2322
public void testIsSupported() {
@@ -26,15 +25,15 @@ public void testIsSupported() {
2625

2726
@Test
2827
public void testRevealSuccess() {
29-
DBusFileMangerRevealPath revealPathService = new DBusFileMangerRevealPath();
28+
DBusSendRevealPathService revealPathService = new DBusSendRevealPathService();
3029
Assumptions.assumeTrue(revealPathService.isSupported());
3130

3231
Assertions.assertDoesNotThrow(() -> revealPathService.reveal(tmpDir));
3332
}
3433

3534
@Test
3635
public void testRevealFail() {
37-
DBusFileMangerRevealPath revealPathService = new DBusFileMangerRevealPath();
36+
DBusSendRevealPathService revealPathService = new DBusSendRevealPathService();
3837
Assumptions.assumeTrue(revealPathService.isSupported());
3938

4039
Assertions.assertThrows(RevealFailedException.class, () -> revealPathService.reveal(tmpDir.resolve("foobar")));

0 commit comments

Comments
 (0)