Skip to content

Commit 3365a7a

Browse files
refined API
1 parent 3c0bc6e commit 3365a7a

File tree

7 files changed

+270
-161
lines changed

7 files changed

+270
-161
lines changed

src/main/java/module-info.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import org.cryptomator.integrations.mount.FilesystemMountProvider;
1+
import org.cryptomator.integrations.mount.MountProvider;
22
import org.cryptomator.integrations.tray.TrayMenuController;
33
import org.cryptomator.integrations.autostart.AutoStartProvider;
44
import org.cryptomator.integrations.keychain.KeychainAccessProvider;
@@ -19,7 +19,7 @@
1919

2020
uses AutoStartProvider;
2121
uses KeychainAccessProvider;
22-
uses FilesystemMountProvider;
22+
uses MountProvider;
2323
uses TrayIntegrationProvider;
2424
uses TrayMenuController;
2525
uses UiAppearanceProvider;

src/main/java/org/cryptomator/integrations/mount/FileSystemMount.java

Lines changed: 0 additions & 68 deletions
This file was deleted.

src/main/java/org/cryptomator/integrations/mount/FilesystemMountProvider.java

Lines changed: 0 additions & 91 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package org.cryptomator.integrations.mount;
2+
3+
import java.nio.file.Path;
4+
import java.util.function.Consumer;
5+
6+
/**
7+
* Handle to control the lifecycle of a mounted file system.
8+
* <p>
9+
* Created by {@link MountBuilder}
10+
*/
11+
public interface Mount extends AutoCloseable {
12+
13+
//TODO: either this or reveal method, not both
14+
Path getAccessPoint();
15+
16+
//TODO: is this needed? why not just let the consumer reveal?
17+
// See WebDAV: LinuxGioMounter and LinuxGvfsMounter -> no path, just a command
18+
void reveal(Consumer<Path> cmd);
19+
20+
/**
21+
* Unmounts the mounted Volume.
22+
* <p>
23+
* If possible, attempt a graceful unmount.
24+
*
25+
* @throws UnmountFailedException If the unmount was not successful.
26+
* @see #unmountForced()
27+
*/
28+
void unmout() throws UnmountFailedException;
29+
30+
/**
31+
* If supported, force-unmount the volume.
32+
*
33+
* @throws UnmountFailedException If the unmount was not successful.
34+
* @throws UnsupportedOperationException If {@link MountFeature#UNMOUNT_FORCED} is not supported
35+
*/
36+
default void unmountForced() throws UnmountFailedException {
37+
throw new UnsupportedOperationException();
38+
}
39+
40+
default void close() throws UnmountFailedException {
41+
unmout();
42+
}
43+
44+
45+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package org.cryptomator.integrations.mount;
2+
3+
import org.jetbrains.annotations.Contract;
4+
import org.jetbrains.annotations.Range;
5+
6+
import java.nio.file.Path;
7+
import java.util.function.Consumer;
8+
9+
/**
10+
* Builder to mount a filesystem.
11+
* <p>
12+
* The setter may attempt to validate the input, but {@link #mount()} may still fail due to missing or invalid (combination of) options.
13+
* This holds especially for {@link MountBuilder#setMountFlags(String)};
14+
*/
15+
public interface MountBuilder {
16+
17+
//TODO: Idea: every setter verifies the set and can throw an IllegalArgumentException
18+
19+
/**
20+
* Sets the mount point.
21+
*
22+
* @param mountPoint Where to mount the volume
23+
* @return <code>this</code>
24+
* @throws UnsupportedOperationException If {@link MountFeature#MOUNT_POINT_EMPTY_DIR} is not supported // TODO: what MOUNT_POINT_* features do we really need?
25+
* @see MountProvider#getDefaultMountPoint(String)
26+
*/
27+
@Contract("_ -> this")
28+
default MountBuilder setMountpoint(Path mountPoint) {
29+
throw new UnsupportedOperationException();
30+
}
31+
32+
// TODO: in what legacy mounter impl is this used?
33+
@Contract("_ -> this")
34+
default MountBuilder setOnExitAction(Consumer<Throwable> onExitAction) {
35+
throw new UnsupportedOperationException();
36+
}
37+
38+
/**
39+
* Sets mount flags.
40+
*
41+
* @param mountFlags Mount flags
42+
* @return <code>this</code>
43+
* @throws UnsupportedOperationException If {@link MountFeature#MOUNT_FLAGS} is not supported
44+
* @see MountProvider#getDefaultMountFlags(String)
45+
*/
46+
@Contract("_ -> this")
47+
default MountBuilder setMountFlags(String mountFlags) {
48+
throw new UnsupportedOperationException();
49+
}
50+
51+
/**
52+
* Instructs the mount to be read-only.
53+
*
54+
* @param mountReadOnly Whether to mount read-only.
55+
* @return <code>this</code>
56+
* @throws UnsupportedOperationException If {@link MountFeature#READ_ONLY} is not supported
57+
*/
58+
@Contract("_ -> this")
59+
default MountBuilder setReadOnly(boolean mountReadOnly) {
60+
throw new UnsupportedOperationException();
61+
}
62+
63+
/**
64+
* Use the given TCP port.
65+
*
66+
* @param port fixed TCP port or 0 to use a system-assigned port
67+
* @return <code>this</code>
68+
* @throws UnsupportedOperationException If {@link MountFeature#PORT} is not supported
69+
*/
70+
@Contract("_ -> this")
71+
default MountBuilder setPort(@Range(from = 0, to = Short.MAX_VALUE) int port) {
72+
throw new UnsupportedOperationException();
73+
}
74+
75+
76+
/**
77+
* Mounts the file system.
78+
*
79+
* @return A mount handle
80+
* @throws MountFailedException If mounting failed
81+
*/
82+
@Contract(" -> new")
83+
Mount mount() throws MountFailedException;
84+
85+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,39 @@
11
package org.cryptomator.integrations.mount;
22

3+
/**
4+
* Describes what aspects of the mount implementation can or should be used.
5+
* <p>
6+
* This may be used to show or hide different configuration options depending on the chosen mount provider.
7+
*/
38
public enum MountFeature {
9+
/**
10+
* The provider supports {@link MountProvider#getDefaultMountFlags(String)}
11+
* and the builder requires {@link MountBuilder#setMountFlags(String)}.
12+
*/
413
MOUNT_FLAGS,
514
MOUNT_POINT_EMPTY_DIR,
615
MOUNT_POINT_DRIVE_LETTER,
716
MOUNT_POINT_PATH_PREFIX,
17+
18+
/**
19+
* The builder supports {@link MountBuilder#setReadOnly(boolean)}
20+
*/
821
READ_ONLY,
22+
23+
/**
24+
* The mount supports {@link Mount#unmountForced()}.
25+
*/
926
UNMOUNT_FORCED,
1027
ON_EXIT_ACTION,
28+
29+
/**
30+
* The provider supports {@link MountProvider#getDefaultPort()}
31+
* and the builder requires {@link MountBuilder#setPort(int)}.
32+
*/
1133
PORT,
34+
35+
/**
36+
* The provider supports {@link MountProvider#getDefaultMountPoint(String)}
37+
*/
1238
DEFAULT_MOUNT_POINT
1339
}

0 commit comments

Comments
 (0)