use of org.syncany.plugins.transfer.files.RemoteFile in project syncany by syncany.
the class PathAwareFeatureTransferManager method upload.
@Override
public void upload(final File localFile, final RemoteFile remoteFile) throws StorageException {
final RemoteFile pathAwareRemoteFile = createPathAwareRemoteFile(remoteFile);
if (!createFolder(pathAwareRemoteFile)) {
throw new StorageException("Unable to create path for " + pathAwareRemoteFile);
}
underlyingTransferManager.upload(localFile, pathAwareRemoteFile);
}
use of org.syncany.plugins.transfer.files.RemoteFile in project syncany by syncany.
the class TransactionAwareFeatureTransferManager method addAndFilterFilesInTransaction.
/**
* Returns a list of remote files, excluding the files in transactions.
* The method is used to hide unfinished transactions from other clients.
*/
protected <T extends RemoteFile> Map<String, T> addAndFilterFilesInTransaction(Class<T> remoteFileClass, Map<String, T> remoteFiles) throws StorageException {
Map<String, T> filteredFiles = new HashMap<String, T>();
Set<TransactionTO> transactions = new HashSet<TransactionTO>();
Set<RemoteFile> dummyDeletedFiles = new HashSet<RemoteFile>();
Set<RemoteFile> filesToIgnore = new HashSet<RemoteFile>();
// Ignore files currently listed in a transaction,
// unless we are listing transaction files
boolean ignoreFilesInTransactions = !remoteFileClass.equals(TransactionRemoteFile.class);
if (ignoreFilesInTransactions) {
transactions = retrieveRemoteTransactions().keySet();
filesToIgnore = getFilesInTransactions(transactions);
dummyDeletedFiles = getDummyDeletedFiles(transactions);
}
for (RemoteFile deletedFile : dummyDeletedFiles) {
if (deletedFile.getClass().equals(remoteFileClass)) {
T concreteDeletedFile = remoteFileClass.cast(deletedFile);
filteredFiles.put(concreteDeletedFile.getName(), concreteDeletedFile);
}
}
for (String fileName : remoteFiles.keySet()) {
if (!filesToIgnore.contains(remoteFiles.get(fileName))) {
filteredFiles.put(fileName, remoteFiles.get(fileName));
}
}
return filteredFiles;
}
use of org.syncany.plugins.transfer.files.RemoteFile in project syncany by syncany.
the class LsRemoteCommand method printResults.
@Override
public void printResults(OperationResult operationResult) {
LsRemoteOperationResult concreteOperationResult = (LsRemoteOperationResult) operationResult;
List<DatabaseRemoteFile> remoteStatus = concreteOperationResult.getUnknownRemoteDatabases();
if (remoteStatus.size() > 0) {
for (RemoteFile unknownRemoteFile : remoteStatus) {
out.println("? " + unknownRemoteFile.getName());
}
} else {
out.println("No remote changes.");
}
}
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());
}
use of org.syncany.plugins.transfer.files.RemoteFile in project syncany by syncany.
the class LocalTransferManager method delete.
@Override
public boolean delete(RemoteFile remoteFile) throws StorageException {
connect();
File repoFile = getRemoteFile(remoteFile);
return !repoFile.exists() || repoFile.delete();
}
Aggregations