浏览代码

Moved #isSupported() in the file, moved #determineMountPoint()

JaniruTEC 5 年之前
父节点
当前提交
f601ff4ce3

+ 29 - 0
main/commons/src/main/java/org/cryptomator/common/vaults/AbstractVolume.java

@@ -0,0 +1,29 @@
+package org.cryptomator.common.vaults;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableSet;
+import org.cryptomator.common.mountpoint.InvalidMountPointException;
+import org.cryptomator.common.mountpoint.MountPointChooser;
+import org.cryptomator.cryptofs.CryptoFileSystem;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.Optional;
+
+public abstract class AbstractVolume implements Volume {
+
+	public Path determineMountPoint() throws InvalidMountPointException {
+		for (MountPointChooser chooser : this.choosers) {
+			Optional<Path> chosenPath = chooser.chooseMountPoint();
+			if (chosenPath.isEmpty()) {
+				//Chooser was applicable, but couldn't find a feasible mountpoint
+				continue;
+			}
+			this.cleanupRequired = chooser.prepare(chosenPath.get()); //Fail entirely if an Exception occurs
+			this.usedChooser = chooser;
+			return chosenPath.get();
+		}
+		String tried = Joiner.on(", ").join(this.choosers.stream().map((mpc) -> mpc.getClass().getTypeName()).collect(ImmutableSet.toImmutableSet()));
+		throw new InvalidMountPointException(String.format("No feasible MountPoint found! Tried %s", tried));
+	}
+}

+ 6 - 25
main/commons/src/main/java/org/cryptomator/common/vaults/DokanyVolume.java

@@ -1,7 +1,5 @@
 package org.cryptomator.common.vaults;
 
-import com.google.common.base.Joiner;
-import com.google.common.collect.ImmutableSet;
 import org.cryptomator.common.mountpoint.InvalidMountPointException;
 import org.cryptomator.common.mountpoint.MountPointChooser;
 import org.cryptomator.common.settings.VaultSettings;
@@ -19,7 +17,7 @@ import java.util.Optional;
 import java.util.Set;
 import java.util.concurrent.ExecutorService;
 
-public class DokanyVolume implements Volume {
+public class DokanyVolume extends AbstractVolume {
 
 	private static final Logger LOG = LoggerFactory.getLogger(DokanyVolume.class);
 
@@ -44,11 +42,6 @@ public class DokanyVolume implements Volume {
 		this.choosers = choosers;
 	}
 
-	@Override
-	public boolean isSupported() {
-		return DokanyVolume.isSupportedStatic();
-	}
-
 	@Override
 	public void mount(CryptoFileSystem fs, String mountFlags) throws InvalidMountPointException, VolumeException {
 		this.mountPoint = determineMountPoint();
@@ -63,23 +56,6 @@ public class DokanyVolume implements Volume {
 		}
 	}
 
-	private Path determineMountPoint() throws InvalidMountPointException {
-		for (MountPointChooser chooser : this.choosers) {
-			Optional<Path> chosenPath = chooser.chooseMountPoint();
-			if (chosenPath.isEmpty()) {
-				//Chooser was applicable, but couldn't find a feasible mountpoint
-				continue;
-			}
-			this.cleanupRequired = chooser.prepare(chosenPath.get()); //Fail entirely if an Exception occurs
-			this.usedChooser = chooser;
-			return chosenPath.get();
-		}
-		String tried = Joiner.on(", ").join(this.choosers.stream()
-				.map((mpc) -> mpc.getClass().getTypeName())
-				.collect(ImmutableSet.toImmutableSet()));
-		throw new InvalidMountPointException(String.format("No feasible MountPoint found! Tried %s", tried));
-	}
-
 	@Override
 	public void reveal() throws VolumeException {
 		boolean success = mount.reveal();
@@ -100,6 +76,11 @@ public class DokanyVolume implements Volume {
 		}
 	}
 
+	@Override
+	public boolean isSupported() {
+		return DokanyVolume.isSupportedStatic();
+	}
+
 	@Override
 	public Optional<Path> getMountPoint() {
 		return Optional.ofNullable(mountPoint);

+ 1 - 20
main/commons/src/main/java/org/cryptomator/common/vaults/FuseVolume.java

@@ -1,8 +1,6 @@
 package org.cryptomator.common.vaults;
 
-import com.google.common.base.Joiner;
 import com.google.common.base.Splitter;
-import com.google.common.collect.ImmutableSet;
 import org.apache.commons.lang3.SystemUtils;
 import org.cryptomator.common.mountpoint.InvalidMountPointException;
 import org.cryptomator.common.mountpoint.MountPointChooser;
@@ -22,7 +20,7 @@ import java.nio.file.Path;
 import java.util.Optional;
 import java.util.Set;
 
-public class FuseVolume implements Volume {
+public class FuseVolume extends AbstractVolume {
 
 	private static final Logger LOG = LoggerFactory.getLogger(FuseVolume.class);
 
@@ -47,23 +45,6 @@ public class FuseVolume implements Volume {
 		mount(fs.getPath("/"), mountFlags);
 	}
 
-	private Path determineMountPoint() throws InvalidMountPointException {
-		for (MountPointChooser chooser : this.choosers) {
-			Optional<Path> chosenPath = chooser.chooseMountPoint();
-			if (chosenPath.isEmpty()) {
-				//Chooser was applicable, but couldn't find a feasible mountpoint
-				continue;
-			}
-			this.cleanupRequired = chooser.prepare(chosenPath.get()); //Fail entirely if an Exception occurs
-			this.usedChooser = chooser;
-			return chosenPath.get();
-		}
-		String tried = Joiner.on(", ").join(this.choosers.stream()
-				.map((mpc) -> mpc.getClass().getTypeName())
-				.collect(ImmutableSet.toImmutableSet()));
-		throw new InvalidMountPointException(String.format("No feasible MountPoint found! Tried %s", tried));
-	}
-
 	private void mount(Path root, String mountFlags) throws VolumeException {
 		try {
 			Mounter mounter = FuseMountFactory.getMounter();