mirror of
https://github.com/cryptomator/cryptomator.git
synced 2024-11-23 03:59:51 +00:00
First prototype: Moved logic of "getCiphertextPath"
Moved logic of "getCiphertextPath" from Vault to VaultState
This commit is contained in:
parent
ca3a11de90
commit
2bad933c85
@ -314,6 +314,10 @@ public class Vault {
|
||||
return vaultSettings.path.get();
|
||||
}
|
||||
|
||||
CryptoFileSystem getCryptoFileSystem() {
|
||||
return cryptoFileSystem.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets from the cleartext path its ciphertext counterpart.
|
||||
*
|
||||
@ -322,23 +326,7 @@ public class Vault {
|
||||
* @throws IllegalStateException if the vault is not unlocked
|
||||
*/
|
||||
public Path getCiphertextPath(Path cleartextPath) throws IOException {
|
||||
if (!state.getValue().equals(VaultState.Value.UNLOCKED)) {
|
||||
throw new IllegalStateException("Vault is not unlocked");
|
||||
}
|
||||
var fs = cryptoFileSystem.get();
|
||||
var osPathSeparator = cleartextPath.getFileSystem().getSeparator();
|
||||
var cryptoFsPathSeparator = fs.getSeparator();
|
||||
|
||||
if (getMountPoint() instanceof Mountpoint.WithPath mp) {
|
||||
var absoluteCryptoFsPath = cryptoFsPathSeparator + mp.path().relativize(cleartextPath).toString();
|
||||
if (!cryptoFsPathSeparator.equals(osPathSeparator)) {
|
||||
absoluteCryptoFsPath = absoluteCryptoFsPath.replace(osPathSeparator, cryptoFsPathSeparator);
|
||||
}
|
||||
var cryptoPath = fs.getPath(absoluteCryptoFsPath);
|
||||
return fs.getCiphertextPath(cryptoPath);
|
||||
} else {
|
||||
throw new UnsupportedOperationException("URI mount points not supported.");
|
||||
}
|
||||
return state.get().getCiphertextPath(this, cleartextPath);
|
||||
}
|
||||
|
||||
public VaultConfigCache getVaultConfigCache() {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.cryptomator.common.vaults;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.cryptomator.integrations.mount.Mountpoint;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -8,6 +9,8 @@ import javax.inject.Inject;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.value.ObservableObjectValue;
|
||||
import javafx.beans.value.ObservableValueBase;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.concurrent.locks.Condition;
|
||||
@ -43,12 +46,40 @@ public class VaultState extends ObservableValueBase<VaultState.Value> implements
|
||||
/**
|
||||
* Vault is unlocked
|
||||
*/
|
||||
UNLOCKED,
|
||||
UNLOCKED {
|
||||
/**
|
||||
* Gets from the cleartext path its ciphertext counterpart.
|
||||
*
|
||||
* @return Local os path to the ciphertext resource
|
||||
* @throws IOException if an I/O error occurs
|
||||
* @throws IllegalStateException if the vault is not unlocked
|
||||
*/
|
||||
Path getCiphertextPath(Vault vault, Path cleartextPath) throws IOException {
|
||||
var fs = vault.getCryptoFileSystem();
|
||||
var osPathSeparator = cleartextPath.getFileSystem().getSeparator();
|
||||
var cryptoFsPathSeparator = fs.getSeparator();
|
||||
|
||||
if (vault.getMountPoint() instanceof Mountpoint.WithPath mp) {
|
||||
var absoluteCryptoFsPath = cryptoFsPathSeparator + mp.path().relativize(cleartextPath).toString();
|
||||
if (!cryptoFsPathSeparator.equals(osPathSeparator)) {
|
||||
absoluteCryptoFsPath = absoluteCryptoFsPath.replace(osPathSeparator, cryptoFsPathSeparator);
|
||||
}
|
||||
var cryptoPath = fs.getPath(absoluteCryptoFsPath);
|
||||
return fs.getCiphertextPath(cryptoPath);
|
||||
} else {
|
||||
throw new UnsupportedOperationException("URI mount points not supported.");
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Unknown state due to preceding unrecoverable exceptions.
|
||||
*/
|
||||
ERROR;
|
||||
|
||||
Path getCiphertextPath(Vault vault, Path cleartextPath) throws IOException {
|
||||
throw new IllegalStateException("Vault is not unlocked");
|
||||
}
|
||||
}
|
||||
|
||||
private final AtomicReference<Value> value;
|
||||
|
Loading…
Reference in New Issue
Block a user