Merge pull request #1512 from cryptomator/feature/refactor-reveal

This commit is contained in:
Armin Schrenk
2021-01-22 11:42:20 +01:00
committed by GitHub
10 changed files with 72 additions and 28 deletions
@@ -52,10 +52,11 @@ public class DokanyVolume extends AbstractVolume {
}
@Override
public void reveal() throws VolumeException {
boolean success = mount.reveal();
if (!success) {
throw new VolumeException("Reveal failed.");
public void reveal(Revealer revealer) throws VolumeException {
try {
mount.reveal(revealer::reveal);
} catch (Exception e) {
throw new VolumeException(e);
}
}
@@ -79,6 +80,7 @@ public class DokanyVolume extends AbstractVolume {
public boolean supportsForcedUnmount() {
return true;
}
@Override
public boolean isSupported() {
return DokanyVolume.isSupportedStatic();
@@ -20,7 +20,6 @@ import javax.inject.Named;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.SortedSet;
import java.util.regex.Pattern;
public class FuseVolume extends AbstractVolume {
@@ -73,11 +72,10 @@ public class FuseVolume extends AbstractVolume {
}
@Override
public void reveal() throws VolumeException {
public void reveal(Revealer revealer) throws VolumeException {
try {
mount.revealInFileManager();
} catch (CommandFailedException e) {
LOG.debug("Revealing the vault in file manger failed: " + e.getMessage());
mount.reveal(revealer::reveal);
} catch (Exception e) {
throw new VolumeException(e);
}
}
@@ -157,8 +157,8 @@ public class Vault {
destroyCryptoFileSystem();
}
public void reveal() throws VolumeException {
volume.reveal();
public void reveal(Volume.Revealer vaultRevealer) throws VolumeException {
volume.reveal(vaultRevealer);
}
// ******************************************************************************
@@ -34,7 +34,15 @@ public interface Volume {
*/
void mount(CryptoFileSystem fs, String mountFlags) throws IOException, VolumeException, InvalidMountPointException;
void reveal() throws VolumeException;
/**
* Reveals the mounted volume.
* <p>
* The given {@code revealer} might be used to do it, but not necessarily.
*
* @param revealer An object capable of revealing the location of the mounted vault to view the content (e.g. in the default file browser).
* @throws VolumeException
*/
void reveal(Revealer revealer) throws VolumeException;
void unmount() throws VolumeException;
@@ -79,4 +87,14 @@ public interface Volume {
}
/**
* Hides and unifies the different Revealer implementations in the different nio-adapters.
*/
@FunctionalInterface
interface Revealer {
void reveal(Path p) throws VolumeException;
}
}
@@ -31,7 +31,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, WindowsDriveLetters windowsDriveLetters) {
@@ -86,11 +85,10 @@ public class WebDavVolume implements Volume {
}
@Override
public void reveal() throws VolumeException {
public void reveal(Revealer revealer) throws VolumeException {
try {
mount.reveal();
} catch (Mounter.CommandFailedException e) {
e.printStackTrace();
mount.reveal(revealer::reveal);
} catch (Exception e) {
throw new VolumeException(e);
}
}
@@ -117,7 +115,7 @@ public class WebDavVolume implements Volume {
@Override
public Optional<Path> getMountPoint() {
return Optional.ofNullable(mountPoint); //TODO
return mount.getMountPoint();
}
@Override