Search in sources :

Example 1 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 2 with RemoteFile

use of org.syncany.plugins.transfer.files.RemoteFile in project syncany by syncany.

the class AbstractTransferManagerTest method uploadDownloadListDelete.

private <T extends RemoteFile> void uploadDownloadListDelete(TransferManager transferManager, File tempFromDir, File tempToDir, Class<T> remoteFileClass, T[] remoteFiles) throws Exception {
    for (RemoteFile remoteFile : remoteFiles) {
        File originalLocalFile = new File(tempFromDir, remoteFile.getName());
        File downloadedLocalFile = new File(tempToDir, remoteFile.getName());
        TestFileUtil.createNonRandomFile(originalLocalFile, 5 * 1024);
        transferManager.upload(originalLocalFile, remoteFile);
        transferManager.download(remoteFile, downloadedLocalFile);
        String checksumOriginalFile = StringUtil.toHex(TestFileUtil.createChecksum(originalLocalFile));
        String checksumDownloadedFile = StringUtil.toHex(TestFileUtil.createChecksum(downloadedLocalFile));
        assertEquals("Uploaded file differs from original file, for file " + originalLocalFile, checksumOriginalFile, checksumDownloadedFile);
    }
    Map<String, T> listLocalFilesAfterUpload = transferManager.list(remoteFileClass);
    assertEquals(remoteFiles.length, listLocalFilesAfterUpload.size());
    for (RemoteFile remoteFile : remoteFiles) {
        transferManager.delete(remoteFile);
    }
    Map<String, T> listLocalFileAfterDelete = transferManager.list(remoteFileClass);
    assertEquals(0, listLocalFileAfterDelete.size());
}
Also used : RemoteFile(org.syncany.plugins.transfer.files.RemoteFile) MasterRemoteFile(org.syncany.plugins.transfer.files.MasterRemoteFile) File(java.io.File) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) MultichunkRemoteFile(org.syncany.plugins.transfer.files.MultichunkRemoteFile) SyncanyRemoteFile(org.syncany.plugins.transfer.files.SyncanyRemoteFile) RemoteFile(org.syncany.plugins.transfer.files.RemoteFile) MasterRemoteFile(org.syncany.plugins.transfer.files.MasterRemoteFile) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) MultichunkRemoteFile(org.syncany.plugins.transfer.files.MultichunkRemoteFile) SyncanyRemoteFile(org.syncany.plugins.transfer.files.SyncanyRemoteFile)

Example 3 with RemoteFile

use of org.syncany.plugins.transfer.files.RemoteFile in project syncany by syncany.

the class RemoteTransaction method commit.

/**
 * Commits this transaction by performing the required upload and
 * delete operations. The method first moves all files to the temporary
 * remote location. If no errors occur, all files are moved to their
 * final location.
 *
 * <p>The method first writes a {@link TransactionRemoteFile} containing
 * all actions to be performed and then uploads this file. Then it uploads
 * new files (added by {@link #upload(File, RemoteFile) upload()} and moves
 * deleted files to a temporary location (deleted by {@link #delete(RemoteFile) delete()}.
 *
 * <p>If this was successful, the transaction file is deleted and the
 * temporary files. After deleting the transaction file, the transaction
 * is successfully committed.
 */
public void commit() throws StorageException {
    logger.log(Level.INFO, "Starting TX.commit() ...");
    if (isEmpty()) {
        logger.log(Level.INFO, "- Empty transaction, not committing anything.");
        return;
    }
    File localTransactionFile = writeLocalTransactionFile();
    TransactionRemoteFile remoteTransactionFile = uploadTransactionFile(localTransactionFile);
    commit(localTransactionFile, remoteTransactionFile);
}
Also used : TransactionRemoteFile(org.syncany.plugins.transfer.files.TransactionRemoteFile) RemoteFile(org.syncany.plugins.transfer.files.RemoteFile) File(java.io.File) TempRemoteFile(org.syncany.plugins.transfer.files.TempRemoteFile) TransactionRemoteFile(org.syncany.plugins.transfer.files.TransactionRemoteFile)

Example 4 with RemoteFile

use of org.syncany.plugins.transfer.files.RemoteFile in project syncany by syncany.

the class RemoteTransaction method moveToFinalLocation.

/**
 * This method constitutes the second step in the committing process. All files have been uploaded, and they are
 * now moved to their final location.
 */
private void moveToFinalLocation() throws StorageException {
    for (ActionTO action : transactionTO.getActions()) {
        if (action.getType().equals(ActionType.UPLOAD)) {
            RemoteFile tempRemoteFile = action.getTempRemoteFile();
            RemoteFile finalRemoteFile = action.getRemoteFile();
            logger.log(Level.INFO, "- Moving temp. file {0} to final location {1} ...", new Object[] { tempRemoteFile, finalRemoteFile });
            transferManager.move(tempRemoteFile, finalRemoteFile);
            action.setStatus(ActionStatus.DONE);
        }
    }
}
Also used : ActionTO(org.syncany.plugins.transfer.to.ActionTO) RemoteFile(org.syncany.plugins.transfer.files.RemoteFile) TempRemoteFile(org.syncany.plugins.transfer.files.TempRemoteFile) TransactionRemoteFile(org.syncany.plugins.transfer.files.TransactionRemoteFile)

Example 5 with RemoteFile

use of org.syncany.plugins.transfer.files.RemoteFile in project syncany by syncany.

the class RemoteTransaction method uploadAndMoveToTempLocation.

/**
 * This method performs the first step for all files in the committing process.
 * For UPLOADs, this is uploading the file to the temporary remote location.
 * For DELETEs, this is moving the file from the original remote location to a temporary remote location.
 * If this is a transaction that is being resumed, the {@link ActionStatus} will show that this part has
 * already been done. In this case, we do not repeat it.
 *
 * This is the expensive part of the committing process, when we are talking about I/O. Hence this is also
 * the most likely part to be interrupted on weak connections.
 */
private void uploadAndMoveToTempLocation() throws StorageException {
    TransactionStats stats = gatherTransactionStats();
    int uploadFileIndex = 0;
    for (ActionTO action : transactionTO.getActions()) {
        if (action.getStatus().equals(ActionStatus.UNSTARTED)) {
            // If we are resuming, this has not been started yet.
            RemoteFile tempRemoteFile = action.getTempRemoteFile();
            if (action.getType().equals(ActionType.UPLOAD)) {
                // The action is an UPLOAD, upload file to temporary remote location
                File localFile = action.getLocalTempLocation();
                long localFileSize = localFile.length();
                eventBus.post(new UpUploadFileInTransactionSyncExternalEvent(config.getLocalDir().getAbsolutePath(), ++uploadFileIndex, stats.totalUploadFileCount, localFileSize, stats.totalUploadSize));
                logger.log(Level.INFO, "- Uploading {0} to temp. file {1} ...", new Object[] { localFile, tempRemoteFile });
                transferManager.upload(localFile, tempRemoteFile);
                action.setStatus(ActionStatus.STARTED);
            } else if (action.getType().equals(ActionType.DELETE)) {
                // The action is a DELETE, move file to temporary remote location.
                RemoteFile remoteFile = action.getRemoteFile();
                try {
                    logger.log(Level.INFO, "- Moving {0} to temp. file {1} ...", new Object[] { remoteFile, tempRemoteFile });
                    transferManager.move(remoteFile, tempRemoteFile);
                } catch (StorageMoveException e) {
                    logger.log(Level.INFO, "  -> FAILED (don't care!), because the remoteFile does not exist: " + remoteFile);
                }
                action.setStatus(ActionStatus.STARTED);
            }
        }
    }
}
Also used : ActionTO(org.syncany.plugins.transfer.to.ActionTO) RemoteFile(org.syncany.plugins.transfer.files.RemoteFile) File(java.io.File) TempRemoteFile(org.syncany.plugins.transfer.files.TempRemoteFile) TransactionRemoteFile(org.syncany.plugins.transfer.files.TransactionRemoteFile) UpUploadFileInTransactionSyncExternalEvent(org.syncany.operations.daemon.messages.UpUploadFileInTransactionSyncExternalEvent) RemoteFile(org.syncany.plugins.transfer.files.RemoteFile) TempRemoteFile(org.syncany.plugins.transfer.files.TempRemoteFile) TransactionRemoteFile(org.syncany.plugins.transfer.files.TransactionRemoteFile)

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