Search in sources :

Example 1 with StorageMoveException

use of org.syncany.plugins.transfer.StorageMoveException in project syncany by syncany.

the class TransactionAwareFeatureTransferManager method rollbackActions.

/**
 * Adds the opposite actions (rollback actions) for the given unfinished actions
 * to the rollback transaction.
 */
private void rollbackActions(List<ActionTO> unfinishedActions) throws StorageException {
    for (ActionTO action : unfinishedActions) {
        logger.log(Level.INFO, "- Needs to be rolled back: " + action);
        switch(action.getType()) {
            case UPLOAD:
                delete(action.getRemoteFile());
                delete(action.getTempRemoteFile());
                break;
            case DELETE:
                try {
                    logger.log(Level.INFO, "- Rollback action: Moving " + action.getTempRemoteFile().getName() + " to " + action.getRemoteFile().getName());
                    move(action.getTempRemoteFile(), action.getRemoteFile());
                } catch (StorageMoveException e) {
                    logger.log(Level.WARNING, "Restoring deleted file failed. This might be a problem if the original: " + action.getRemoteFile() + " also does not exist.", e);
                }
                break;
            default:
                throw new RuntimeException("Transaction contains invalid type: " + action.getType() + ". This should not happen.");
        }
    }
}
Also used : ActionTO(org.syncany.plugins.transfer.to.ActionTO) StorageMoveException(org.syncany.plugins.transfer.StorageMoveException)

Example 2 with StorageMoveException

use of org.syncany.plugins.transfer.StorageMoveException in project syncany by syncany.

the class LocalTransferManager method move.

@Override
public void move(RemoteFile sourceFile, RemoteFile targetFile) throws StorageException {
    connect();
    File sourceRemoteFile = getRemoteFile(sourceFile);
    File targetRemoteFile = getRemoteFile(targetFile);
    if (!sourceRemoteFile.exists()) {
        throw new StorageMoveException("Unable to move file " + sourceFile + " because it does not exist.");
    }
    try {
        FileUtils.moveFile(sourceRemoteFile, targetRemoteFile);
    } catch (IOException ex) {
        throw new StorageException("Unable to move file " + sourceRemoteFile + " to destination " + targetRemoteFile, ex);
    }
}
Also used : StorageMoveException(org.syncany.plugins.transfer.StorageMoveException) 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)

Aggregations

StorageMoveException (org.syncany.plugins.transfer.StorageMoveException)2 File (java.io.File)1 IOException (java.io.IOException)1 StorageException (org.syncany.plugins.transfer.StorageException)1 ActionRemoteFile (org.syncany.plugins.transfer.files.ActionRemoteFile)1 CleanupRemoteFile (org.syncany.plugins.transfer.files.CleanupRemoteFile)1 DatabaseRemoteFile (org.syncany.plugins.transfer.files.DatabaseRemoteFile)1 MultichunkRemoteFile (org.syncany.plugins.transfer.files.MultichunkRemoteFile)1 RemoteFile (org.syncany.plugins.transfer.files.RemoteFile)1 SyncanyRemoteFile (org.syncany.plugins.transfer.files.SyncanyRemoteFile)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