Search in sources :

Example 46 with Path

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);
}
Also used : Path(java.nio.file.Path)

Example 47 with Path

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();
        }
    }
}
Also used : Path(java.nio.file.Path) IOException(java.io.IOException)

Example 48 with Path

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.");
}
Also used : Path(java.nio.file.Path) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Example 49 with Path

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();
        }
    });
}
Also used : Path(java.nio.file.Path)

Example 50 with Path

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;
}
Also used : Path(java.nio.file.Path) BytesRef(org.apache.lucene.util.BytesRef)

Aggregations

Path (java.nio.file.Path)4893 Test (org.junit.Test)1960 IOException (java.io.IOException)829 File (java.io.File)445 SourcePath (com.facebook.buck.rules.SourcePath)389 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)334 BuildTarget (com.facebook.buck.model.BuildTarget)320 ArrayList (java.util.ArrayList)313 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)250 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)231 PathSourcePath (com.facebook.buck.rules.PathSourcePath)226 InputStream (java.io.InputStream)210 ImmutableList (com.google.common.collect.ImmutableList)175 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)166 HashMap (java.util.HashMap)159 ImmutableMap (com.google.common.collect.ImmutableMap)157 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)154 Matchers.containsString (org.hamcrest.Matchers.containsString)148 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)147 Map (java.util.Map)146