Переглянути джерело

relaxed "vault not empty" check

Sebastian Stenzel 8 роки тому
батько
коміт
a63bcfbaa2

+ 4 - 2
main/ui/src/main/java/org/cryptomator/ui/controllers/InitializeController.java

@@ -10,8 +10,8 @@
 package org.cryptomator.ui.controllers;
 
 import java.io.IOException;
-import java.io.UncheckedIOException;
 import java.net.URL;
+import java.nio.file.DirectoryNotEmptyException;
 import java.nio.file.FileAlreadyExistsException;
 import java.util.Objects;
 import java.util.Optional;
@@ -124,7 +124,9 @@ public class InitializeController extends LocalizedFXMLViewController {
 			listener.ifPresent(this::invokeListenerLater);
 		} catch (FileAlreadyExistsException ex) {
 			messageLabel.setText(localization.getString("initialize.messageLabel.alreadyInitialized"));
-		} catch (UncheckedIOException | IOException ex) {
+		} catch (DirectoryNotEmptyException ex) {
+			messageLabel.setText(localization.getString("initialize.messageLabel.notEmpty"));
+		} catch (IOException ex) {
 			LOG.error("I/O Exception", ex);
 			messageLabel.setText(localization.getString("initialize.messageLabel.initializationFailed"));
 		} finally {

+ 6 - 2
main/ui/src/main/java/org/cryptomator/ui/model/Vault.java

@@ -12,6 +12,7 @@ import static org.apache.commons.lang3.StringUtils.stripStart;
 
 import java.io.IOException;
 import java.io.UncheckedIOException;
+import java.nio.file.DirectoryNotEmptyException;
 import java.nio.file.FileAlreadyExistsException;
 import java.nio.file.Files;
 import java.nio.file.Path;
@@ -30,6 +31,7 @@ import org.apache.commons.lang3.SystemUtils;
 import org.cryptomator.common.LazyInitializer;
 import org.cryptomator.common.Optionals;
 import org.cryptomator.crypto.engine.InvalidPassphraseException;
+import org.cryptomator.filesystem.File;
 import org.cryptomator.filesystem.FileSystem;
 import org.cryptomator.filesystem.charsets.NormalizedNameFileSystem;
 import org.cryptomator.filesystem.crypto.CryptoFileSystemDelegate;
@@ -109,8 +111,10 @@ public class Vault implements CryptoFileSystemDelegate {
 	public void create(CharSequence passphrase) throws IOException {
 		try {
 			FileSystem fs = getNioFileSystem();
-			if (fs.children().count() > 0) {
-				throw new FileAlreadyExistsException(null, null, "Vault location not empty.");
+			if (fs.files().map(File::name).filter(s -> s.endsWith(VAULT_FILE_EXTENSION)).count() > 0) {
+				throw new FileAlreadyExistsException("masterkey.cryptomator", null, "Vault location not empty.");
+			} else if (fs.folders().count() > 0) {
+				throw new DirectoryNotEmptyException(fs.toString());
 			}
 			cryptoFileSystemFactory.initializeNew(fs, passphrase);
 		} catch (UncheckedIOException e) {

+ 1 - 0
main/ui/src/main/resources/localization/en.txt

@@ -26,6 +26,7 @@ initialize.label.password=Password
 initialize.label.retypePassword=Retype password
 initialize.button.ok=Create vault
 initialize.messageLabel.alreadyInitialized=Vault already initialized
+initialize.messageLabel.notEmpty=Vault not empty
 initialize.messageLabel.initializationFailed=Could not initialize vault. See log file for details.
 initialize.messageLabel.passwordStrength.0=Very weak
 initialize.messageLabel.passwordStrength.1=Weak