use of org.syncany.plugins.transfer.files.RemoteFile in project syncany by syncany.
the class LocalTransferManager method upload.
@Override
public void upload(File localFile, RemoteFile remoteFile) throws StorageException {
connect();
File repoFile = getRemoteFile(remoteFile);
File tempRepoFile = new File(getAbsoluteParentDirectory(repoFile) + File.separator + ".temp-" + repoFile.getName());
// Do not overwrite files with same size!
if (repoFile.exists() && repoFile.length() == localFile.length()) {
return;
}
// No such local file
if (!localFile.exists()) {
throw new StorageException("No such file on local disk: " + localFile);
}
try {
FileUtils.copyFile(localFile, tempRepoFile);
FileUtils.moveFile(tempRepoFile, repoFile);
} catch (IOException ex) {
throw new StorageException("Unable to copy file " + localFile + " to local repository " + repoFile, ex);
}
}
use of org.syncany.plugins.transfer.files.RemoteFile in project syncany by syncany.
the class LocalTransferManager method download.
@Override
public void download(RemoteFile remoteFile, File localFile) throws StorageException {
connect();
File repoFile = getRemoteFile(remoteFile);
if (!repoFile.exists()) {
throw new StorageFileNotFoundException("No such file in local repository: " + repoFile);
}
try {
File tempLocalFile = createTempFile("local-tm-download");
tempLocalFile.deleteOnExit();
FileUtils.copyFile(repoFile, tempLocalFile);
localFile.delete();
FileUtils.moveFile(tempLocalFile, localFile);
tempLocalFile.delete();
} catch (IOException ex) {
throw new StorageException("Unable to copy file " + repoFile + " from local repository to " + localFile, ex);
}
}
use of org.syncany.plugins.transfer.files.RemoteFile in project syncany by syncany.
the class PathAwareFeatureTransferManager method move.
@Override
public void move(final RemoteFile sourceFile, final RemoteFile targetFile) throws StorageException {
final RemoteFile pathAwareSourceFile = createPathAwareRemoteFile(sourceFile);
final RemoteFile pathAwareTargetFile = createPathAwareRemoteFile(targetFile);
if (!createFolder(pathAwareTargetFile)) {
throw new StorageException("Unable to create path for " + pathAwareTargetFile);
}
underlyingTransferManager.move(pathAwareSourceFile, pathAwareTargetFile);
removeFolder(pathAwareSourceFile);
}
use of org.syncany.plugins.transfer.files.RemoteFile in project syncany by syncany.
the class PathAwareFeatureTransferManager method delete.
@Override
public boolean delete(final RemoteFile remoteFile) throws StorageException {
RemoteFile pathAwareRemoteFile = createPathAwareRemoteFile(remoteFile);
boolean fileDeleted = underlyingTransferManager.delete(pathAwareRemoteFile);
boolean folderDeleted = removeFolder(pathAwareRemoteFile);
return fileDeleted && folderDeleted;
}
use of org.syncany.plugins.transfer.files.RemoteFile in project syncany by syncany.
the class CleanupOperation method mergeRemoteFiles.
/**
* This method deletes all remote database files and writes new ones for each client using the local database.
* To make the state clear and prevent issues with replacing files, new database files are given a higher number
* than all existing database files.
* Both the deletions and the new files added to the current @{link RemoteTransaction}.
*/
private void mergeRemoteFiles() throws Exception {
// Retrieve all database versions
Map<String, List<DatabaseRemoteFile>> allDatabaseFilesMap = retrieveAllRemoteDatabaseFiles();
boolean needMerge = needMerge(allDatabaseFilesMap);
if (!needMerge) {
logger.log(Level.INFO, "- No purging happened. Number of database files does not exceed threshold. Not merging remote files.");
return;
}
// Now do the merge!
logger.log(Level.INFO, "- Merge remote files ...");
List<DatabaseRemoteFile> allToDeleteDatabaseFiles = new ArrayList<DatabaseRemoteFile>();
Map<File, DatabaseRemoteFile> allMergedDatabaseFiles = new TreeMap<File, DatabaseRemoteFile>();
for (String client : allDatabaseFilesMap.keySet()) {
List<DatabaseRemoteFile> clientDatabaseFiles = allDatabaseFilesMap.get(client);
Collections.sort(clientDatabaseFiles);
logger.log(Level.INFO, "Databases: " + clientDatabaseFiles);
// 1. Determine files to delete remotely
List<DatabaseRemoteFile> toDeleteDatabaseFiles = new ArrayList<DatabaseRemoteFile>(clientDatabaseFiles);
allToDeleteDatabaseFiles.addAll(toDeleteDatabaseFiles);
// 2. Write new database file and save it in allMergedDatabaseFiles
writeMergeFile(client, allMergedDatabaseFiles);
}
rememberDatabases(allMergedDatabaseFiles);
// Queue old databases for deletion
for (RemoteFile toDeleteRemoteFile : allToDeleteDatabaseFiles) {
logger.log(Level.INFO, " + Deleting remote file " + toDeleteRemoteFile + " ...");
remoteTransaction.delete(toDeleteRemoteFile);
}
// Queue new databases for uploading
for (File lastLocalMergeDatabaseFile : allMergedDatabaseFiles.keySet()) {
RemoteFile lastRemoteMergeDatabaseFile = allMergedDatabaseFiles.get(lastLocalMergeDatabaseFile);
logger.log(Level.INFO, " + Uploading new file {0} from local file {1} ...", new Object[] { lastRemoteMergeDatabaseFile, lastLocalMergeDatabaseFile });
remoteTransaction.upload(lastLocalMergeDatabaseFile, lastRemoteMergeDatabaseFile);
}
finishMerging();
// Update stats
result.setMergedDatabaseFilesCount(allToDeleteDatabaseFiles.size());
}
Aggregations