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);
}
}
}
}
Aggregations