Refactored changes, cleaned up

Changed visibility of methods
Removed Logger from AbstractVolume
Moved mountPoint and #getMountPoint()
Renamed fuseMnt to mount in FuseVol (as in DokanyVol)
Removed unnecessary mountPoint-field from WebDavVolume
This commit is contained in:
JaniruTEC
2020-08-18 21:27:13 +02:00
parent cbef54f05c
commit 16462d05c8
4 changed files with 17 additions and 30 deletions
@@ -4,8 +4,6 @@ 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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.file.Path;
import java.util.Optional;
@@ -13,10 +11,10 @@ import java.util.Set;
public abstract class AbstractVolume implements Volume {
private static final Logger LOG = LoggerFactory.getLogger(AbstractVolume.class);
private final Set<MountPointChooser> choosers;
protected Path mountPoint;
//Cleanup
private boolean cleanupRequired;
private MountPointChooser usedChooser;
@@ -25,7 +23,7 @@ public abstract class AbstractVolume implements Volume {
this.choosers = choosers;
}
public Path determineMountPoint() throws InvalidMountPointException {
protected Path determineMountPoint() throws InvalidMountPointException {
for (MountPointChooser chooser : this.choosers) {
Optional<Path> chosenPath = chooser.chooseMountPoint();
if (chosenPath.isEmpty()) {
@@ -40,9 +38,14 @@ public abstract class AbstractVolume implements Volume {
throw new InvalidMountPointException(String.format("No feasible MountPoint found! Tried %s", tried));
}
public void cleanupMountPoint() {
protected void cleanupMountPoint() {
if (this.cleanupRequired) {
this.usedChooser.cleanup(this.mountPoint);
}
}
@Override
public Optional<Path> getMountPoint() {
return Optional.ofNullable(mountPoint);
}
}
@@ -12,8 +12,6 @@ import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Named;
import java.nio.file.Path;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ExecutorService;
@@ -27,7 +25,6 @@ public class DokanyVolume extends AbstractVolume {
private final MountFactory mountFactory;
private Mount mount;
private Path mountPoint;
@Inject
public DokanyVolume(VaultSettings vaultSettings, ExecutorService executorService, @Named("orderedValidMountPointChoosers") Set<MountPointChooser> choosers) {
@@ -69,11 +66,6 @@ public class DokanyVolume extends AbstractVolume {
return DokanyVolume.isSupportedStatic();
}
@Override
public Optional<Path> getMountPoint() {
return Optional.ofNullable(mountPoint);
}
@Override
public MountPointRequirement getMountPointRequirement() {
return MountPointRequirement.EMPTY_MOUNT_POINT;
@@ -17,15 +17,13 @@ import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Named;
import java.nio.file.Path;
import java.util.Optional;
import java.util.Set;
public class FuseVolume extends AbstractVolume {
private static final Logger LOG = LoggerFactory.getLogger(FuseVolume.class);
private Mount fuseMnt;
private Path mountPoint;
private Mount mount;
@Inject
public FuseVolume(@Named("orderedValidMountPointChoosers") Set<MountPointChooser> choosers) {
@@ -45,7 +43,7 @@ public class FuseVolume extends AbstractVolume {
EnvironmentVariables envVars = EnvironmentVariables.create() //
.withFlags(splitFlags(mountFlags)).withMountPoint(mountPoint) //
.build();
this.fuseMnt = mounter.mount(root, envVars);
this.mount = mounter.mount(root, envVars);
} catch (CommandFailedException | FuseNotSupportedException e) {
throw new VolumeException("Unable to mount Filesystem", e);
}
@@ -58,7 +56,7 @@ public class FuseVolume extends AbstractVolume {
@Override
public void reveal() throws VolumeException {
try {
fuseMnt.revealInFileManager();
mount.revealInFileManager();
} catch (CommandFailedException e) {
LOG.debug("Revealing the vault in file manger failed: " + e.getMessage());
throw new VolumeException(e);
@@ -73,8 +71,8 @@ public class FuseVolume extends AbstractVolume {
@Override
public synchronized void unmountForced() throws VolumeException {
try {
fuseMnt.unmountForced();
fuseMnt.close();
mount.unmountForced();
mount.close();
} catch (CommandFailedException e) {
throw new VolumeException(e);
}
@@ -84,8 +82,8 @@ public class FuseVolume extends AbstractVolume {
@Override
public synchronized void unmount() throws VolumeException {
try {
fuseMnt.unmount();
fuseMnt.close();
mount.unmount();
mount.close();
} catch (CommandFailedException e) {
throw new VolumeException(e);
}
@@ -97,11 +95,6 @@ public class FuseVolume extends AbstractVolume {
return FuseVolume.isSupportedStatic();
}
@Override
public Optional<Path> getMountPoint() {
return Optional.ofNullable(mountPoint);
}
@Override
public MountPointRequirement getMountPointRequirement() {
return SystemUtils.IS_OS_WINDOWS ? MountPointRequirement.PARENT_NO_MOUNT_POINT : MountPointRequirement.EMPTY_MOUNT_POINT;
@@ -27,7 +27,6 @@ public class WebDavVolume implements Volume {
private WebDavServer server;
private WebDavServletController servlet;
private Mounter.Mount mount;
private Path mountPoint;
@Inject
public WebDavVolume(Provider<WebDavServer> serverProvider, VaultSettings vaultSettings, Settings settings) {
@@ -98,7 +97,7 @@ public class WebDavVolume implements Volume {
@Override
public Optional<Path> getMountPoint() {
return Optional.ofNullable(mountPoint);
return Optional.empty();
}
@Override