mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-17 10:11:27 +00:00
Fixed possible racecondition at Vault initialization
Fixed possible racecondition at Vault initialization: VaulSettings were read before the Vault was fully initialized resulting in breakage of the code if the excact order was to be changed.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package org.cryptomator.common.mountpoint;
|
||||
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
import org.cryptomator.common.settings.VaultSettings;
|
||||
import org.cryptomator.common.vaults.Vault;
|
||||
|
||||
import java.nio.file.Path;
|
||||
@@ -10,10 +9,10 @@ import java.util.Optional;
|
||||
|
||||
public class CustomDriveLetterChooser implements MountPointChooser {
|
||||
|
||||
private final VaultSettings vaultSettings;
|
||||
private final Vault vault;
|
||||
|
||||
public CustomDriveLetterChooser(Vault vault) {
|
||||
this.vaultSettings = vault.getVaultSettings();
|
||||
this.vault = vault;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -23,6 +22,6 @@ public class CustomDriveLetterChooser implements MountPointChooser {
|
||||
|
||||
@Override
|
||||
public Optional<Path> chooseMountPoint() {
|
||||
return this.vaultSettings.getWinDriveLetter().map(letter -> letter.charAt(0) + ":\\").map(Paths::get);
|
||||
return this.vault.getVaultSettings().getWinDriveLetter().map(letter -> letter.charAt(0) + ":\\").map(Paths::get);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.cryptomator.common.mountpoint;
|
||||
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
import org.cryptomator.common.settings.VaultSettings;
|
||||
import org.cryptomator.common.vaults.Vault;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -21,16 +20,16 @@ public class CustomMountPointChooser implements MountPointChooser {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CustomMountPointChooser.class);
|
||||
|
||||
private final VaultSettings vaultSettings;
|
||||
private final Vault vault;
|
||||
|
||||
public CustomMountPointChooser(Vault vault) {
|
||||
this.vaultSettings = vault.getVaultSettings();
|
||||
this.vault = vault;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Path> chooseMountPoint() {
|
||||
//VaultSettings#getCustomMountPath already checks whether the saved custom mountpoint should be used
|
||||
return this.vaultSettings.getCustomMountPath().map(Paths::get);
|
||||
return this.vault.getVaultSettings().getCustomMountPath().map(Paths::get);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.cryptomator.common.mountpoint;
|
||||
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
import org.cryptomator.common.Environment;
|
||||
import org.cryptomator.common.settings.VaultSettings;
|
||||
import org.cryptomator.common.vaults.Vault;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -18,11 +17,11 @@ public class TemporaryMountPointChooser implements MountPointChooser {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TemporaryMountPointChooser.class);
|
||||
private static final int MAX_TMPMOUNTPOINT_CREATION_RETRIES = 10;
|
||||
|
||||
private final VaultSettings vaultSettings;
|
||||
private final Vault vault;
|
||||
private final Environment environment;
|
||||
|
||||
public TemporaryMountPointChooser(Vault vault, Environment environment) {
|
||||
this.vaultSettings = vault.getVaultSettings();
|
||||
this.vault = vault;
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
@@ -39,7 +38,7 @@ public class TemporaryMountPointChooser implements MountPointChooser {
|
||||
public Optional<Path> chooseMountPoint() {
|
||||
//Shouldn't throw, but let's keep #orElseThrow in case we made a mistake and the check in #isApplicable failed
|
||||
Path parent = this.environment.getMountPointsDir().orElseThrow();
|
||||
String basename = this.vaultSettings.getId();
|
||||
String basename = this.vault.getVaultSettings().getId();
|
||||
for (int i = 0; i < MAX_TMPMOUNTPOINT_CREATION_RETRIES; i++) {
|
||||
Path mountPoint = parent.resolve(basename + "_" + i);
|
||||
if (Files.notExists(mountPoint)) {
|
||||
|
||||
Reference in New Issue
Block a user