Parcourir la source

fixing bug where the mountName of the vault is initially set as the default one

Armin Schrenk il y a 4 ans
Parent
commit
7e0ffb43a6

+ 12 - 6
main/commons/src/main/java/org/cryptomator/common/settings/VaultSettings.java

@@ -63,12 +63,18 @@ public class VaultSettings {
 		return new Observable[]{path, mountName, winDriveLetter, unlockAfterStartup, revealAfterMount, useCustomMountPath, customMountPath, usesReadOnlyMode, mountFlags, filenameLengthLimit, actionAfterUnlock};
 	}
 
-	private void deriveMountNameFromPathOrUseDefault(Path path) {
-		if (StringUtils.isBlank(mountName.get())) {
-			if (path != null && path.getFileName() != null) {
-				mountName.set(normalizeMountName(path.getFileName().toString()));
-			} else {
-				mountName.set(DEFAULT_MOUNT_NAME);
+	private void deriveMountNameFromPathOrUseDefault(Path newPath) {
+		final boolean mountNameSet = !StringUtils.isBlank(mountName.get());
+		final boolean dirnameExists = (newPath != null) && (newPath.getFileName() != null);
+
+		if (!mountNameSet && dirnameExists) {
+			mountName.set(normalizeMountName(newPath.getFileName().toString()));
+		} else if (!mountNameSet && !dirnameExists) {
+			mountName.set(DEFAULT_MOUNT_NAME+id);
+		}else if (mountNameSet && dirnameExists) {
+			if(mountName.get().equals(DEFAULT_MOUNT_NAME+id)){
+				//this is okay, since this function is only executed if the path changes (aka, the vault is created or added)
+				mountName.set(newPath.getFileName().toString());
 			}
 		}
 	}