Search in sources :

Example 1 with UpUploadFileInTransactionSyncExternalEvent

use of org.syncany.operations.daemon.messages.UpUploadFileInTransactionSyncExternalEvent 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

File (java.io.File)1 UpUploadFileInTransactionSyncExternalEvent (org.syncany.operations.daemon.messages.UpUploadFileInTransactionSyncExternalEvent)1 RemoteFile (org.syncany.plugins.transfer.files.RemoteFile)1 TempRemoteFile (org.syncany.plugins.transfer.files.TempRemoteFile)1 TransactionRemoteFile (org.syncany.plugins.transfer.files.TransactionRemoteFile)1 ActionTO (org.syncany.plugins.transfer.to.ActionTO)1