Parcourir la source

implemented “change password” etc

Sebastian Stenzel il y a 8 ans
Parent
commit
b75b9781c1

+ 1 - 1
main/ui/src/main/java/org/cryptomator/ui/controllers/MainController.java

@@ -202,7 +202,7 @@ public class MainController extends LocalizedFXMLViewController {
 	@FXML
 	private void didClickAddExistingVaults(ActionEvent event) {
 		final FileChooser fileChooser = new FileChooser();
-		fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Cryptomator Masterkey", "*" + Vault.VAULT_FILE_EXTENSION));
+		fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Cryptomator Masterkey", "*.cryptomator"));
 		final List<File> files = fileChooser.showOpenMultipleDialog(mainWindow);
 		if (files != null) {
 			for (final File file : files) {

+ 3 - 3
main/ui/src/main/java/org/cryptomator/ui/model/UpgradeVersion3DropBundleExtension.java

@@ -41,7 +41,7 @@ class UpgradeVersion3DropBundleExtension extends UpgradeStrategy {
 		String fmt = localization.getString("upgrade.version3dropBundleExtension.msg");
 		Path path = vault.getPath();
 		String oldVaultName = path.getFileName().toString();
-		String newVaultName = StringUtils.removeEnd(oldVaultName, Vault.VAULT_FILE_EXTENSION);
+		String newVaultName = StringUtils.removeEnd(oldVaultName, ".cryptomator");
 		return String.format(fmt, oldVaultName, newVaultName);
 	}
 
@@ -49,7 +49,7 @@ class UpgradeVersion3DropBundleExtension extends UpgradeStrategy {
 	protected void upgrade(Vault vault, Cryptor cryptor) throws UpgradeFailedException {
 		Path path = vault.getPath();
 		String oldVaultName = path.getFileName().toString();
-		String newVaultName = StringUtils.removeEnd(oldVaultName, Vault.VAULT_FILE_EXTENSION);
+		String newVaultName = StringUtils.removeEnd(oldVaultName, ".cryptomator");
 		Path newPath = path.resolveSibling(newVaultName);
 		if (Files.exists(newPath)) {
 			String fmt = localization.getString("upgrade.version3dropBundleExtension.err.alreadyExists");
@@ -73,7 +73,7 @@ class UpgradeVersion3DropBundleExtension extends UpgradeStrategy {
 	@Override
 	public boolean isApplicable(Vault vault) {
 		Path vaultPath = vault.getPath();
-		if (vaultPath.toString().endsWith(Vault.VAULT_FILE_EXTENSION)) {
+		if (vaultPath.toString().endsWith(".cryptomator")) {
 			return super.isApplicable(vault);
 		} else {
 			return false;

+ 17 - 12
main/ui/src/main/java/org/cryptomator/ui/model/Vault.java

@@ -9,7 +9,9 @@
 package org.cryptomator.ui.model;
 
 import java.io.IOException;
-import java.io.UncheckedIOException;
+import java.nio.file.DirectoryNotEmptyException;
+import java.nio.file.DirectoryStream;
+import java.nio.file.FileAlreadyExistsException;
 import java.nio.file.FileSystem;
 import java.nio.file.Files;
 import java.nio.file.Path;
@@ -49,9 +51,6 @@ public class Vault {
 
 	private static final Logger LOG = LoggerFactory.getLogger(Vault.class);
 
-	@Deprecated
-	public static final String VAULT_FILE_EXTENSION = ".cryptomator";
-
 	private final VaultSettings vaultSettings;
 	private final WebDavServer server;
 	private final DeferredCloser closer;
@@ -85,12 +84,22 @@ public class Vault {
 	}
 
 	public void create(CharSequence passphrase) throws IOException {
-		// TODO overheadhunter/markuskreusch check (via cryptofs) if already existing? if not, just call:
-		getCryptoFileSystem(passphrase); // implicitly creates a non-existing vault
+		try (DirectoryStream<Path> stream = Files.newDirectoryStream(getPath())) {
+			for (Path file : stream) {
+				if (!file.getFileName().toString().startsWith(".")) {
+					throw new DirectoryNotEmptyException(getPath().toString());
+				}
+			}
+		}
+		if (!isValidVaultDirectory()) {
+			getCryptoFileSystem(passphrase); // implicitly creates a non-existing vault
+		} else {
+			throw new FileAlreadyExistsException(getPath().toString());
+		}
 	}
 
 	public void changePassphrase(CharSequence oldPassphrase, CharSequence newPassphrase) throws IOException, InvalidPassphraseException {
-		// TODO overheadhunter/markuskreusch implement in cryptofs
+		CryptoFileSystemProvider.changePassphrase(getPath(), oldPassphrase, newPassphrase);
 	}
 
 	public synchronized void activateFrontend(CharSequence passphrase) {
@@ -187,11 +196,7 @@ public class Vault {
 	}
 
 	public boolean isValidVaultDirectory() {
-		try {
-			return doesVaultDirectoryExist(); // TODO overheadhunter/markuskreusch: && CryptoFileSystemProvider.isValidVaultStructure(getPath());
-		} catch (UncheckedIOException e) {
-			return false;
-		}
+		return CryptoFileSystemProvider.containsVault(getPath());
 	}
 
 	public BooleanProperty unlockedProperty() {