Renamed CommandFailedException to VolumeException

This commit is contained in:
Sebastian Stenzel
2018-06-15 09:48:46 +02:00
parent 5515258af1
commit 5b45893c7b
6 changed files with 51 additions and 50 deletions

View File

@@ -74,7 +74,7 @@ public class AutoUnlocker {
try {
vault.unlock(CharBuffer.wrap(storedPw));
revealSilently(vault);
} catch (IOException | CryptoException | CommandFailedException e) {
} catch (IOException | CryptoException | Volume.VolumeException e) {
LOG.error("Auto unlock failed.", e);
} finally {
Arrays.fill(storedPw, ' ');
@@ -87,7 +87,7 @@ public class AutoUnlocker {
}
try {
mountedVault.reveal();
} catch (CommandFailedException e) {
} catch (Volume.VolumeException e) {
LOG.error("Auto unlock succeded, but revealing the drive failed.", e);
}
}

View File

@@ -1,17 +0,0 @@
package org.cryptomator.ui.model;
public class CommandFailedException extends Exception {
public CommandFailedException(String message) {
super(message);
}
public CommandFailedException(Throwable cause) {
super(cause);
}
public CommandFailedException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@@ -12,6 +12,7 @@ import javax.inject.Inject;
import org.apache.commons.lang3.SystemUtils;
import org.cryptomator.common.settings.VaultSettings;
import org.cryptomator.cryptofs.CryptoFileSystem;
import org.cryptomator.frontend.fuse.mount.CommandFailedException;
import org.cryptomator.frontend.fuse.mount.EnvironmentVariables;
import org.cryptomator.frontend.fuse.mount.FuseMountFactory;
import org.cryptomator.frontend.fuse.mount.FuseNotSupportedException;
@@ -44,7 +45,7 @@ public class FuseVolume implements Volume {
}
@Override
public void mount(CryptoFileSystem fs) throws IOException, FuseNotSupportedException, CommandFailedException {
public void mount(CryptoFileSystem fs) throws IOException, FuseNotSupportedException, VolumeException {
this.cfs = fs;
String mountPath;
if (vaultSettings.usesIndividualMountPath().get()) {
@@ -77,34 +78,34 @@ public class FuseVolume implements Volume {
}
}
private void mount() throws CommandFailedException {
private void mount() throws VolumeException {
try {
EnvironmentVariables envVars = EnvironmentVariables.create()
.withMountName(vaultSettings.mountName().getValue())
.withMountPath(mountPath)
.build();
this.fuseMnt = FuseMountFactory.getMounter().mount(cfs.getPath("/"), envVars);
} catch (org.cryptomator.frontend.fuse.mount.CommandFailedException e) {
throw new CommandFailedException("Unable to mount Filesystem", e);
} catch (CommandFailedException e) {
throw new VolumeException("Unable to mount Filesystem", e);
}
}
@Override
public void reveal() throws CommandFailedException {
public void reveal() throws VolumeException {
try {
fuseMnt.revealInFileManager();
} catch (org.cryptomator.frontend.fuse.mount.CommandFailedException e) {
} catch (CommandFailedException e) {
LOG.info("Revealing the vault in file manger failed: " + e.getMessage());
throw new CommandFailedException(e);
throw new VolumeException(e);
}
}
@Override
public synchronized void unmount() throws CommandFailedException {
public synchronized void unmount() throws VolumeException {
try {
fuseMnt.close();
} catch (org.cryptomator.frontend.fuse.mount.CommandFailedException e) {
throw new CommandFailedException(e);
} catch (CommandFailedException e) {
throw new VolumeException(e);
}
cleanup();
}

View File

@@ -97,7 +97,7 @@ public class Vault {
CryptoFileSystemProvider.changePassphrase(getPath(), MASTERKEY_FILENAME, oldPassphrase, newPassphrase);
}
public synchronized void unlock(CharSequence passphrase) throws CryptoException, IOException, CommandFailedException {
public synchronized void unlock(CharSequence passphrase) throws CryptoException, IOException, Volume.VolumeException {
Platform.runLater(() -> {
state.set(State.PROCESSING);
});
@@ -108,7 +108,7 @@ public class Vault {
});
}
public synchronized void lock(boolean forced) throws CommandFailedException {
public synchronized void lock(boolean forced) throws Volume.VolumeException {
Platform.runLater(() -> {
state.set(State.PROCESSING);
});
@@ -136,11 +136,11 @@ public class Vault {
public void prepareForShutdown() {
try {
lock(false);
} catch (CommandFailedException e) {
} catch (Volume.VolumeException e) {
if (volume.supportsForcedUnmount()) {
try {
lock(true);
} catch (CommandFailedException e1) {
} catch (Volume.VolumeException e1) {
LOG.warn("Failed to force lock vault.", e1);
}
} else {
@@ -149,7 +149,7 @@ public class Vault {
}
}
public void reveal() throws CommandFailedException {
public void reveal() throws Volume.VolumeException {
volume.reveal();
}

View File

@@ -20,13 +20,11 @@ public interface Volume {
* @param fs
* @throws IOException
*/
void mount(CryptoFileSystem fs) throws IOException, CommandFailedException;
void mount(CryptoFileSystem fs) throws IOException, VolumeException;
default void reveal() throws CommandFailedException {
throw new CommandFailedException("Not implemented.");
}
void reveal() throws VolumeException;
void unmount() throws CommandFailedException;
void unmount() throws VolumeException;
// optional forced unmounting:
@@ -34,8 +32,27 @@ public interface Volume {
return false;
}
default void unmountForced() throws CommandFailedException {
throw new CommandFailedException("Operation not supported.");
default void unmountForced() throws VolumeException {
throw new VolumeException("Operation not supported.");
}
/**
* Exception thrown when a volume-specific command such as mount/unmount/reveal failed.
*/
class VolumeException extends Exception {
public VolumeException(String message) {
super(message);
}
public VolumeException(Throwable cause) {
super(cause);
}
public VolumeException(String message, Throwable cause) {
super(message, cause);
}
}
}

View File

@@ -36,7 +36,7 @@ public class WebDavVolume implements Volume {
}
@Override
public void mount(CryptoFileSystem fs) throws CommandFailedException {
public void mount(CryptoFileSystem fs) throws VolumeException {
if (server == null) {
server = serverProvider.get();
}
@@ -48,7 +48,7 @@ public class WebDavVolume implements Volume {
mount();
}
private void mount() throws CommandFailedException {
private void mount() throws VolumeException {
if (servlet == null) {
throw new IllegalStateException("Mounting requires unlocked WebDAV servlet.");
}
@@ -61,36 +61,36 @@ public class WebDavVolume implements Volume {
this.mount = servlet.mount(mountParams); // might block this thread for a while
} catch (Mounter.CommandFailedException e) {
e.printStackTrace();
throw new CommandFailedException(e);
throw new VolumeException(e);
}
}
@Override
public void reveal() throws CommandFailedException {
public void reveal() throws VolumeException {
try {
mount.reveal();
} catch (Mounter.CommandFailedException e) {
e.printStackTrace();
throw new CommandFailedException(e);
throw new VolumeException(e);
}
}
@Override
public synchronized void unmount() throws CommandFailedException {
public synchronized void unmount() throws VolumeException {
try {
mount.unmount();
} catch (Mounter.CommandFailedException e) {
throw new CommandFailedException(e);
throw new VolumeException(e);
}
cleanup();
}
@Override
public synchronized void unmountForced() throws CommandFailedException {
public synchronized void unmountForced() throws VolumeException {
try {
mount.forced().orElseThrow(IllegalStateException::new).unmount();
} catch (Mounter.CommandFailedException e) {
throw new CommandFailedException(e);
throw new VolumeException(e);
}
cleanup();
}