Search in sources :

Example 1 with NormalizedPath

use of org.syncany.util.NormalizedPath in project syncany by syncany.

the class RestoreFileSystemAction method findTargetPath.

private NormalizedPath findTargetPath() throws Exception {
    NormalizedPath targetPath = null;
    if (relativeTargetPath == null) {
        String restoredSuffix = "restored version " + fileVersion2.getVersion();
        targetPath = new NormalizedPath(config.getLocalDir(), fileVersion2.getPath()).withSuffix(restoredSuffix, false);
    } else {
        targetPath = new NormalizedPath(config.getLocalDir(), relativeTargetPath);
    }
    return targetPath;
}
Also used : NormalizedPath(org.syncany.util.NormalizedPath)

Example 2 with NormalizedPath

use of org.syncany.util.NormalizedPath in project syncany by syncany.

the class FileCreatingFileSystemAction method createFolder.

protected void createFolder(FileVersion targetFileVersion) throws Exception {
    NormalizedPath targetDirPath = new NormalizedPath(config.getLocalDir(), targetFileVersion.getPath());
    logger.log(Level.INFO, "     - Creating folder at " + targetFileVersion + " ...");
    try {
        // Clean filename
        if (targetDirPath.hasIllegalChars()) {
            targetDirPath = targetDirPath.toCreatable("filename conflict", true);
            logger.log(Level.INFO, "     - Had illegal chars, cleaned to " + targetDirPath);
        }
        // Try creating it
        createFolder(targetDirPath);
        setFileAttributes(targetFileVersion, targetDirPath.toFile());
    } catch (Exception e) {
        throw new RuntimeException("What to do here?!", e);
    }
}
Also used : NormalizedPath(org.syncany.util.NormalizedPath)

Example 3 with NormalizedPath

use of org.syncany.util.NormalizedPath in project syncany by syncany.

the class FileSystemAction method moveFileToFinalLocation.

protected File moveFileToFinalLocation(File reconstructedFileInCache, FileVersion targetFileVersion) throws IOException {
    NormalizedPath originalPath = new NormalizedPath(config.getLocalDir(), targetFileVersion.getPath());
    NormalizedPath targetPath = originalPath;
    try {
        // Clean filename
        if (targetPath.hasIllegalChars()) {
            targetPath = targetPath.toCreatable("filename conflict", true);
        }
        // Try creating folder
        createFolder(targetPath.getParent());
    } catch (Exception e) {
        throw new RuntimeException("What to do here?!");
    }
    // Try moving file to final destination
    try {
        FileUtils.moveFile(reconstructedFileInCache, targetPath.toFile());
    } catch (FileExistsException e) {
        logger.log(Level.FINE, "File already existed", e);
        moveToConflictFile(targetPath);
    } catch (Exception e) {
        throw new RuntimeException("What to do here?!");
    }
    return targetPath.toFile();
}
Also used : NormalizedPath(org.syncany.util.NormalizedPath) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) FileExistsException(org.apache.commons.io.FileExistsException) FileExistsException(org.apache.commons.io.FileExistsException)

Example 4 with NormalizedPath

use of org.syncany.util.NormalizedPath in project syncany by syncany.

the class FileSystemAction method moveToConflictFile.

protected void moveToConflictFile(FileVersion targetFileVersion) throws IOException {
    NormalizedPath targetConflictingFile = new NormalizedPath(config.getLocalDir(), targetFileVersion.getPath());
    moveToConflictFile(targetConflictingFile);
}
Also used : NormalizedPath(org.syncany.util.NormalizedPath)

Example 5 with NormalizedPath

use of org.syncany.util.NormalizedPath in project syncany by syncany.

the class FileSystemAction method moveToConflictFile.

protected void moveToConflictFile(NormalizedPath conflictingPath) throws IOException {
    if (!FileUtil.exists(conflictingPath.toFile())) {
        logger.log(Level.INFO, "     - Creation of conflict file not necessary. Locally conflicting file vanished from " + conflictingPath);
        return;
    }
    int attempts = 0;
    while (attempts++ < 10) {
        NormalizedPath conflictedCopyPath = null;
        try {
            conflictedCopyPath = findConflictFilename(conflictingPath);
            logger.log(Level.INFO, "     - Local version conflicts, moving local file " + conflictingPath + " to " + conflictedCopyPath + " ...");
            if (conflictingPath.toFile().isDirectory()) {
                FileUtils.moveDirectory(conflictingPath.toFile(), conflictedCopyPath.toFile());
            } else {
                FileUtils.moveFile(conflictingPath.toFile(), conflictedCopyPath.toFile());
            }
            // Success!
            break;
        } catch (FileExistsException e) {
            logger.log(Level.SEVERE, "     - Cannot create conflict file; attempt = " + attempts + " for file: " + conflictedCopyPath, e);
        } catch (FileNotFoundException e) {
            logger.log(Level.INFO, "     - Conflict file vanished. Don't care!", e);
        } catch (Exception e) {
            throw new RuntimeException("What to do here?", e);
        }
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) NormalizedPath(org.syncany.util.NormalizedPath) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) FileExistsException(org.apache.commons.io.FileExistsException) FileExistsException(org.apache.commons.io.FileExistsException)

Aggregations

NormalizedPath (org.syncany.util.NormalizedPath)7 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 FileExistsException (org.apache.commons.io.FileExistsException)2 File (java.io.File)1 Test (org.junit.Test)1