Added Logger, moved cleanup, moved choosing

This commit is contained in:
JaniruTEC
2020-08-18 19:49:24 +02:00
parent f601ff4ce3
commit cbef54f05c
3 changed files with 23 additions and 28 deletions

View File

@@ -4,14 +4,27 @@ 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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Optional;
import java.util.Set;
public abstract class AbstractVolume implements Volume {
private static final Logger LOG = LoggerFactory.getLogger(AbstractVolume.class);
private final Set<MountPointChooser> choosers;
//Cleanup
private boolean cleanupRequired;
private MountPointChooser usedChooser;
public AbstractVolume(Set<MountPointChooser> choosers) {
this.choosers = choosers;
}
public Path determineMountPoint() throws InvalidMountPointException {
for (MountPointChooser chooser : this.choosers) {
Optional<Path> chosenPath = chooser.chooseMountPoint();
@@ -26,4 +39,10 @@ public abstract class AbstractVolume implements Volume {
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));
}
public void cleanupMountPoint() {
if (this.cleanupRequired) {
this.usedChooser.cleanup(this.mountPoint);
}
}
}

View File

@@ -26,20 +26,14 @@ public class DokanyVolume extends AbstractVolume {
private final VaultSettings vaultSettings;
private final MountFactory mountFactory;
private final Set<MountPointChooser> choosers;
private Mount mount;
private Path mountPoint;
//Cleanup
private boolean cleanupRequired;
private MountPointChooser usedChooser;
@Inject
public DokanyVolume(VaultSettings vaultSettings, ExecutorService executorService, @Named("orderedValidMountPointChoosers") Set<MountPointChooser> choosers) {
super(choosers);
this.vaultSettings = vaultSettings;
this.mountFactory = new MountFactory(executorService);
this.choosers = choosers;
}
@Override
@@ -70,12 +64,6 @@ public class DokanyVolume extends AbstractVolume {
cleanupMountPoint();
}
private void cleanupMountPoint() {
if (this.cleanupRequired) {
this.usedChooser.cleanup(this.mountPoint);
}
}
@Override
public boolean isSupported() {
return DokanyVolume.isSupportedStatic();

View File

@@ -24,18 +24,12 @@ public class FuseVolume extends AbstractVolume {
private static final Logger LOG = LoggerFactory.getLogger(FuseVolume.class);
private final Set<MountPointChooser> choosers;
private Mount fuseMnt;
private Path mountPoint;
//Cleanup
private boolean cleanupRequired;
private MountPointChooser usedChooser;
@Inject
public FuseVolume(@Named("orderedValidMountPointChoosers") Set<MountPointChooser> choosers) {
this.choosers = choosers;
super(choosers);
}
@Override
@@ -98,12 +92,6 @@ public class FuseVolume extends AbstractVolume {
cleanupMountPoint();
}
private void cleanupMountPoint() {
if (this.cleanupRequired) {
this.usedChooser.cleanup(this.mountPoint);
}
}
@Override
public boolean isSupported() {
return FuseVolume.isSupportedStatic();