From 4e5edc834fe09018c8a16df88469b0d7f72d5ce9 Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Wed, 28 Jun 2017 11:10:35 +0200 Subject: [PATCH] fixes #526 --- .../cryptomator/common/LazyInitializer.java | 3 +-- .../ui/controllers/UnlockController.java | 4 +++ .../cryptomator/ui/model/AutoUnlocker.java | 3 ++- .../java/org/cryptomator/ui/model/Vault.java | 27 +++++++++---------- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/main/commons/src/main/java/org/cryptomator/common/LazyInitializer.java b/main/commons/src/main/java/org/cryptomator/common/LazyInitializer.java index de32e792b..d58d5af36 100644 --- a/main/commons/src/main/java/org/cryptomator/common/LazyInitializer.java +++ b/main/commons/src/main/java/org/cryptomator/common/LazyInitializer.java @@ -48,7 +48,7 @@ public final class LazyInitializer { try { return reference.updateAndGet(invokeFactoryIfNull(factory)); } catch (InitializationException e) { - Throwables.throwIfUnchecked(e); + Throwables.throwIfUnchecked(e.getCause()); Throwables.throwIfInstanceOf(e.getCause(), exceptionType); throw e; } @@ -61,7 +61,6 @@ public final class LazyInitializer { try { return factory.get(); } catch (Exception e) { - Throwables.throwIfUnchecked(e); // don't catch unchecked exceptions throw new InitializationException(e); } } else { diff --git a/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockController.java b/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockController.java index dbdbdd10e..bd13a8e56 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockController.java @@ -8,6 +8,7 @@ ******************************************************************************/ package org.cryptomator.ui.controllers; +import java.io.IOException; import java.util.Arrays; import java.util.Comparator; import java.util.Objects; @@ -372,6 +373,9 @@ public class UnlockController implements ViewController { }).onError(ServerLifecycleException.class, e -> { LOG.error("Unlock failed for technical reasons.", e); messageText.setText(localization.getString("unlock.errorMessage.unlockFailed")); + }).onError(IOException.class, e -> { + LOG.error("Unlock failed for technical reasons.", e); + messageText.setText(localization.getString("unlock.errorMessage.unlockFailed")); }).andFinally(() -> { if (!savePassword.isSelected()) { passwordField.swipe(); diff --git a/main/ui/src/main/java/org/cryptomator/ui/model/AutoUnlocker.java b/main/ui/src/main/java/org/cryptomator/ui/model/AutoUnlocker.java index a4a18f109..3d5ac4201 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/model/AutoUnlocker.java +++ b/main/ui/src/main/java/org/cryptomator/ui/model/AutoUnlocker.java @@ -5,6 +5,7 @@ *******************************************************************************/ package org.cryptomator.ui.model; +import java.io.IOException; import java.nio.CharBuffer; import java.util.Arrays; import java.util.Collection; @@ -74,7 +75,7 @@ public class AutoUnlocker { try { vault.unlock(CharBuffer.wrap(storedPw)); mountSilently(vault); - } catch (CryptoException e) { + } catch (IOException | CryptoException e) { LOG.error("Auto unlock failed.", e); } finally { Arrays.fill(storedPw, ' '); diff --git a/main/ui/src/main/java/org/cryptomator/ui/model/Vault.java b/main/ui/src/main/java/org/cryptomator/ui/model/Vault.java index 4faa8971f..23c76429b 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/model/Vault.java +++ b/main/ui/src/main/java/org/cryptomator/ui/model/Vault.java @@ -14,6 +14,7 @@ import java.nio.file.DirectoryStream; import java.nio.file.FileAlreadyExistsException; import java.nio.file.FileSystem; import java.nio.file.Files; +import java.nio.file.NoSuchFileException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Objects; @@ -84,11 +85,11 @@ public class Vault { // Commands // ********************************************************************************/ - private CryptoFileSystem getCryptoFileSystem(CharSequence passphrase) throws IOException, InvalidPassphraseException, CryptoException { + private CryptoFileSystem getCryptoFileSystem(CharSequence passphrase) throws NoSuchFileException, IOException, InvalidPassphraseException, CryptoException { return LazyInitializer.initializeLazily(cryptoFileSystem, () -> unlockCryptoFileSystem(passphrase), IOException.class); } - private CryptoFileSystem unlockCryptoFileSystem(CharSequence passphrase) throws IOException, InvalidPassphraseException, CryptoException { + private CryptoFileSystem unlockCryptoFileSystem(CharSequence passphrase) throws NoSuchFileException, IOException, InvalidPassphraseException, CryptoException { CryptoFileSystemProperties fsProps = CryptoFileSystemProperties.cryptoFileSystemProperties() // .withPassphrase(passphrase) // .withFlags() // @@ -116,20 +117,16 @@ public class Vault { CryptoFileSystemProvider.changePassphrase(getPath(), MASTERKEY_FILENAME, oldPassphrase, newPassphrase); } - public synchronized void unlock(CharSequence passphrase) throws InvalidPassphraseException, ServerLifecycleException { - try { - FileSystem fs = getCryptoFileSystem(passphrase); - if (!server.isRunning()) { - server.start(); - } - servlet = server.createWebDavServlet(fs.getPath("/"), vaultSettings.getId() + "/" + vaultSettings.mountName().get()); - servlet.start(); - Platform.runLater(() -> { - state.set(State.UNLOCKED); - }); - } catch (IOException e) { - LOG.error("Unable to provide filesystem", e); + public synchronized void unlock(CharSequence passphrase) throws ServerLifecycleException, CryptoException, IOException { + FileSystem fs = getCryptoFileSystem(passphrase); + if (!server.isRunning()) { + server.start(); } + servlet = server.createWebDavServlet(fs.getPath("/"), vaultSettings.getId() + "/" + vaultSettings.mountName().get()); + servlet.start(); + Platform.runLater(() -> { + state.set(State.UNLOCKED); + }); } public synchronized void mount() throws CommandFailedException {