Search in sources :

Example 11 with RemoteFile

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);
    }
}
Also used : IOException(java.io.IOException) 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) StorageException(org.syncany.plugins.transfer.StorageException)

Example 12 with RemoteFile

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);
    }
}
Also used : StorageFileNotFoundException(org.syncany.plugins.transfer.StorageFileNotFoundException) IOException(java.io.IOException) 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) StorageException(org.syncany.plugins.transfer.StorageException)

Example 13 with RemoteFile

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

Example 14 with RemoteFile

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

Example 15 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)

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