Search in sources :

Example 6 with RemoteFile

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);
}
Also used : StorageException(org.syncany.plugins.transfer.StorageException) RemoteFile(org.syncany.plugins.transfer.files.RemoteFile) MultichunkRemoteFile(org.syncany.plugins.transfer.files.MultichunkRemoteFile)

Example 7 with RemoteFile

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;
}
Also used : TransactionRemoteFile(org.syncany.plugins.transfer.files.TransactionRemoteFile) HashMap(java.util.HashMap) RemoteFile(org.syncany.plugins.transfer.files.RemoteFile) TempRemoteFile(org.syncany.plugins.transfer.files.TempRemoteFile) TransactionRemoteFile(org.syncany.plugins.transfer.files.TransactionRemoteFile) HashSet(java.util.HashSet) TransactionTO(org.syncany.plugins.transfer.to.TransactionTO)

Example 8 with RemoteFile

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.");
    }
}
Also used : LsRemoteOperationResult(org.syncany.operations.ls_remote.LsRemoteOperationResult) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) RemoteFile(org.syncany.plugins.transfer.files.RemoteFile)

Example 9 with RemoteFile

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());
}
Also used : DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap) RemoteFile(org.syncany.plugins.transfer.files.RemoteFile) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) CleanupRemoteFile(org.syncany.plugins.transfer.files.CleanupRemoteFile) File(java.io.File) MultichunkRemoteFile(org.syncany.plugins.transfer.files.MultichunkRemoteFile) RemoteFile(org.syncany.plugins.transfer.files.RemoteFile) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) CleanupRemoteFile(org.syncany.plugins.transfer.files.CleanupRemoteFile) MultichunkRemoteFile(org.syncany.plugins.transfer.files.MultichunkRemoteFile)

Example 10 with RemoteFile

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();
}
Also used : RemoteFile(org.syncany.plugins.transfer.files.RemoteFile) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) SyncanyRemoteFile(org.syncany.plugins.transfer.files.SyncanyRemoteFile) TempRemoteFile(org.syncany.plugins.transfer.files.TempRemoteFile) ActionRemoteFile(org.syncany.plugins.transfer.files.ActionRemoteFile) TransactionRemoteFile(org.syncany.plugins.transfer.files.TransactionRemoteFile) CleanupRemoteFile(org.syncany.plugins.transfer.files.CleanupRemoteFile) File(java.io.File) MultichunkRemoteFile(org.syncany.plugins.transfer.files.MultichunkRemoteFile)

Aggregations

RemoteFile (org.syncany.plugins.transfer.files.RemoteFile)18 MultichunkRemoteFile (org.syncany.plugins.transfer.files.MultichunkRemoteFile)11 File (java.io.File)10 TempRemoteFile (org.syncany.plugins.transfer.files.TempRemoteFile)10 TransactionRemoteFile (org.syncany.plugins.transfer.files.TransactionRemoteFile)10 DatabaseRemoteFile (org.syncany.plugins.transfer.files.DatabaseRemoteFile)9 StorageException (org.syncany.plugins.transfer.StorageException)7 SyncanyRemoteFile (org.syncany.plugins.transfer.files.SyncanyRemoteFile)7 ActionRemoteFile (org.syncany.plugins.transfer.files.ActionRemoteFile)5 CleanupRemoteFile (org.syncany.plugins.transfer.files.CleanupRemoteFile)5 IOException (java.io.IOException)3 MasterRemoteFile (org.syncany.plugins.transfer.files.MasterRemoteFile)3 ActionTO (org.syncany.plugins.transfer.to.ActionTO)3 FilenameFilter (java.io.FilenameFilter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 Test (org.junit.Test)1