Search in sources :

Example 6 with TempRemoteFile

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

the class RemoteTransaction method upload.

/**
 * Adds a file to this transaction. Generates a temporary file to store it.
 */
public void upload(File localFile, RemoteFile remoteFile) throws StorageException {
    TempRemoteFile temporaryRemoteFile = new TempRemoteFile(remoteFile);
    logger.log(Level.INFO, "- Adding file to TX for UPLOAD: " + localFile + " -> Temp. remote file: " + temporaryRemoteFile + ", final location: " + remoteFile);
    ActionTO action = new ActionTO();
    action.setType(ActionType.UPLOAD);
    action.setLocalTempLocation(localFile);
    action.setRemoteLocation(remoteFile);
    action.setRemoteTempLocation(temporaryRemoteFile);
    transactionTO.addAction(action);
}
Also used : TempRemoteFile(org.syncany.plugins.transfer.files.TempRemoteFile) ActionTO(org.syncany.plugins.transfer.to.ActionTO)

Example 7 with TempRemoteFile

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

the class RemoteTransaction method deleteTempRemoteFiles.

/**
 * This method deletes the temporary remote files that were the result of deleted files.
 *
 * Actually deleting remote files is done after finishing the transaction, because
 * it cannot be rolled back! If this fails, the temporary files will eventually
 * be cleaned up by Cleanup and download will not download these, because
 * they are not in any transaction file.
 */
private void deleteTempRemoteFiles() throws StorageException {
    boolean success = true;
    for (ActionTO action : transactionTO.getActions()) {
        if (action.getStatus().equals(ActionStatus.STARTED)) {
            // If we are resuming, this action has not been comopleted.
            if (action.getType().equals(ActionType.DELETE)) {
                RemoteFile tempRemoteFile = action.getTempRemoteFile();
                logger.log(Level.INFO, "- Deleting temp. file {0}  ...", new Object[] { tempRemoteFile });
                try {
                    transferManager.delete(tempRemoteFile);
                } catch (Exception e) {
                    logger.log(Level.INFO, "Failed to delete: " + tempRemoteFile, " because of: " + e);
                    success = false;
                }
                action.setStatus(ActionStatus.DONE);
            }
        }
    }
    if (success) {
        logger.log(Level.INFO, "END of TX.delTemp(): Sucessfully deleted final files.");
    } else {
        logger.log(Level.INFO, "END of TX.delTemp(): Did not succesfully delete all files!");
    }
}
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)

Aggregations

TempRemoteFile (org.syncany.plugins.transfer.files.TempRemoteFile)7 ActionTO (org.syncany.plugins.transfer.to.ActionTO)7 TransactionRemoteFile (org.syncany.plugins.transfer.files.TransactionRemoteFile)4 RemoteFile (org.syncany.plugins.transfer.files.RemoteFile)3 TransactionTO (org.syncany.plugins.transfer.to.TransactionTO)2 File (java.io.File)1 HashSet (java.util.HashSet)1 UpUploadFileInTransactionSyncExternalEvent (org.syncany.operations.daemon.messages.UpUploadFileInTransactionSyncExternalEvent)1 StorageFileNotFoundException (org.syncany.plugins.transfer.StorageFileNotFoundException)1