Fix getCiphertextPath for Windows again.

This commit is contained in:
Armin Schrenk
2023-02-14 17:39:34 +01:00
parent a7b2802f34
commit c5c5e297b7
2 changed files with 18 additions and 12 deletions

View File

@@ -316,18 +316,29 @@ public class Vault {
/**
* Gets from the cleartext path its ciphertext counterpart.
* The cleartext path has to start from the vault root (by starting with "/").
*
* @return Local os path to the ciphertext resource
* @throws IOException if an I/O error occurs
* @throws IllegalStateException if the vault is not unlocked
*/
public Path getCiphertextPath(String cleartextPath) throws IOException {
if (!cleartextPath.startsWith("/")) {
throw new IllegalArgumentException("Input path must be absolute from vault root by starting with \"/\".");
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 cryptoPath = fs.getPath(cleartextPath);
return fs.getCiphertextPath(cryptoPath);
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.");
}
}
public VaultConfigCache getVaultConfigCache() {

View File

@@ -166,12 +166,7 @@ public class VaultDetailUnlockedController implements FxController {
return Optional.empty();
}
try {
var accessPoint = mountPoint.getValue();
var cleartextPath = path.toString().substring(accessPoint.length());
if (!cleartextPath.startsWith("/")) {
cleartextPath = "/" + cleartextPath;
}
return Optional.of(vault.get().getCiphertextPath(cleartextPath));
return Optional.of(vault.get().getCiphertextPath(path));
} catch (IOException e) {
LOG.warn("Unable to get ciphertext path from path: {}", path, e);
return Optional.empty();