Skip to content

Commit

Permalink
only remove .cryptomator extension for vault version 3
Browse files Browse the repository at this point in the history
  • Loading branch information
overheadhunter committed Jul 7, 2016
1 parent eb3cfd6 commit 8a3e097
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.cryptomator.ui.model;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;

Expand Down Expand Up @@ -86,7 +87,24 @@ protected void upgrade(Vault vault, Cryptor cryptor) throws UpgradeFailedExcepti

@Override
public boolean isApplicable(Vault vault) {
return vault.path().getValue().getFileName().toString().endsWith(Vault.VAULT_FILE_EXTENSION);
Path vaultPath = vault.path().getValue();
if (vaultPath.toString().endsWith(Vault.VAULT_FILE_EXTENSION)) {
final Path masterkeyFile = vaultPath.resolve(Constants.MASTERKEY_FILENAME);
try {
if (Files.isRegularFile(masterkeyFile)) {
final String keyContents = new String(Files.readAllBytes(masterkeyFile), StandardCharsets.UTF_8);
return keyContents.contains("\"version\":3") || keyContents.contains("\"version\": 3");
} else {
LOG.warn("Not a file: {}", masterkeyFile);
return false;
}
} catch (IOException e) {
LOG.warn("Could not determine, whether upgrade is applicable.", e);
return false;
}
} else {
return false;
}
}

}

0 comments on commit 8a3e097

Please sign in to comment.