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;
}
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);
}
}
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();
}
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);
}
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);
}
}
}
Aggregations