From 8bb925fd93a1e5aed1da32516b8a6b0376a89ea1 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Mon, 18 Jan 2021 18:41:21 +0100 Subject: [PATCH] fixes #1509 --- .../org/cryptomator/common/vaults/Vault.java | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/main/commons/src/main/java/org/cryptomator/common/vaults/Vault.java b/main/commons/src/main/java/org/cryptomator/common/vaults/Vault.java index 5205d0fdd..bf268eda0 100644 --- a/main/commons/src/main/java/org/cryptomator/common/vaults/Vault.java +++ b/main/commons/src/main/java/org/cryptomator/common/vaults/Vault.java @@ -121,12 +121,28 @@ public class Vault { return CryptoFileSystemProvider.newFileSystem(getPath(), fsProps); } + private void destroyCryptoFileSystem() { + CryptoFileSystem fs = cryptoFileSystem.getAndSet(null); + if (fs != null) { + try { + fs.close(); + } catch (IOException e) { + LOG.error("Error closing file system.", e); + } + } + } + public synchronized void unlock(CharSequence passphrase) throws CryptoException, IOException, VolumeException, InvalidMountPointException { if (cryptoFileSystem.get() == null) { CryptoFileSystem fs = createCryptoFileSystem(passphrase); cryptoFileSystem.set(fs); - volume = volumeProvider.get(); - volume.mount(fs, getEffectiveMountFlags()); + try { + volume = volumeProvider.get(); + volume.mount(fs, getEffectiveMountFlags()); + } catch (IOException | InvalidMountPointException | VolumeException e) { + destroyCryptoFileSystem(); + throw e; + } } else { throw new IllegalStateException("Already unlocked."); } @@ -138,14 +154,7 @@ public class Vault { } else { volume.unmount(); } - CryptoFileSystem fs = cryptoFileSystem.getAndSet(null); - if (fs != null) { - try { - fs.close(); - } catch (IOException e) { - LOG.error("Error closing file system.", e); - } - } + destroyCryptoFileSystem(); } public void reveal() throws VolumeException {