use of java.nio.file.Path in project cryptomator by cryptomator.
the class UpgradeVersion3DropBundleExtension method getMessage.
@Override
public String getMessage(Vault vault) {
String fmt = localization.getString("upgrade.version3dropBundleExtension.msg");
Path path = vault.getPath();
String oldVaultName = path.getFileName().toString();
String newVaultName = StringUtils.removeEnd(oldVaultName, ".cryptomator");
return String.format(fmt, oldVaultName, newVaultName);
}
use of java.nio.file.Path in project cryptomator by cryptomator.
the class UpgradeVersion3DropBundleExtension method upgrade.
@Override
protected void upgrade(Vault vault, Cryptor cryptor) throws UpgradeFailedException {
Path path = vault.getPath();
String oldVaultName = path.getFileName().toString();
String newVaultName = StringUtils.removeEnd(oldVaultName, ".cryptomator");
Path newPath = path.resolveSibling(newVaultName);
if (Files.exists(newPath)) {
String fmt = localization.getString("upgrade.version3dropBundleExtension.err.alreadyExists");
String msg = String.format(fmt, newPath);
throw new UpgradeFailedException(msg);
} else {
try {
LOG.info("Renaming {} to {}", path, newPath.getFileName());
Files.move(path, path.resolveSibling(newVaultName));
Platform.runLater(() -> {
vault.getVaultSettings().path().set(newPath);
});
} catch (IOException e) {
LOG.error("Vault migration failed", e);
throw new UpgradeFailedException();
}
}
}
use of java.nio.file.Path in project cryptomator by cryptomator.
the class UpgradeVersion3to4 method upgrade.
@Override
protected void upgrade(Vault vault, Cryptor cryptor) throws UpgradeFailedException {
Path dataDir = vault.getPath().resolve("d");
Path metadataDir = vault.getPath().resolve("m");
if (!Files.isDirectory(dataDir)) {
// empty vault. no migration needed.
return;
}
try {
Files.walkFileTree(dataDir, new FileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
String name = file.getFileName().toString();
if (name.endsWith(LONG_FILENAME_SUFFIX)) {
migrateLong(metadataDir, file);
} else {
migrate(file, attrs);
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
throw exc;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
LOG.error("Migration failed.", e);
throw new UpgradeFailedException(localization.getString("upgrade.version3to4.err.io"));
}
LOG.info("Migration finished.");
}
use of java.nio.file.Path in project cryptomator by cryptomator.
the class Vault method displayablePath.
public Binding<String> displayablePath() {
Path homeDir = Paths.get(SystemUtils.USER_HOME);
return EasyBind.map(vaultSettings.path(), p -> {
if (p.startsWith(homeDir)) {
Path relativePath = homeDir.relativize(p);
String homePrefix = SystemUtils.IS_OS_WINDOWS ? "~\\" : "~/";
return homePrefix + relativePath.toString();
} else {
return p.toString();
}
});
}
use of java.nio.file.Path in project crate by crate.
the class InternalBlobTableInfoFactory method blobsPath.
private BytesRef blobsPath(Settings indexMetaDataSettings) {
BytesRef blobsPath;
String blobsPathStr = indexMetaDataSettings.get(BlobIndicesService.SETTING_INDEX_BLOBS_PATH);
if (blobsPathStr != null) {
blobsPath = new BytesRef(blobsPathStr);
} else {
Path path = globalBlobPath;
if (path != null) {
blobsPath = new BytesRef(path.toString());
} else {
// TODO: should we set this to null because there is no special blobPath?
Path[] dataFiles = environment.dataFiles();
blobsPath = new BytesRef(dataFiles[0].toString());
}
}
return blobsPath;
}
Aggregations