Search in sources :

Example 1 with StorageFileNotFoundException

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

the class LocalTransferManager method download.

@Override
public void download(RemoteFile remoteFile, File localFile) throws StorageException {
    connect();
    File repoFile = getRemoteFile(remoteFile);
    if (!repoFile.exists()) {
        throw new StorageFileNotFoundException("No such file in local repository: " + repoFile);
    }
    try {
        File tempLocalFile = createTempFile("local-tm-download");
        tempLocalFile.deleteOnExit();
        FileUtils.copyFile(repoFile, tempLocalFile);
        localFile.delete();
        FileUtils.moveFile(tempLocalFile, localFile);
        tempLocalFile.delete();
    } catch (IOException ex) {
        throw new StorageException("Unable to copy file " + repoFile + " from local repository to " + localFile, ex);
    }
}
Also used : StorageFileNotFoundException(org.syncany.plugins.transfer.StorageFileNotFoundException) 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)

Example 2 with StorageFileNotFoundException

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

the class TransactionAwareFeatureTransferManager method downloadDeletedTempFileInTransaction.

/**
	 * Downloads all transaction files and looks for the corresponding temporary file
	 * for the given remote file. If there is a temporary file, the file is downloaded
	 * instead of the original file.
	 *
	 * <p>This method is <b>expensive</b>, but it is only called by {@link #download(RemoteFile, File) download()}
	 * if a file does not exist.
	 */
private void downloadDeletedTempFileInTransaction(RemoteFile remoteFile, File localFile) throws StorageException {
    logger.log(Level.INFO, "File {0} not found, checking if it is being deleted ...", remoteFile.getName());
    Set<TransactionTO> transactions = retrieveRemoteTransactions().keySet();
    TempRemoteFile tempRemoteFile = null;
    // Find file: If the file is being deleted and the name matches, download temporary file instead.
    for (TransactionTO transaction : transactions) {
        for (ActionTO action : transaction.getActions()) {
            if (action.getType().equals(ActionType.DELETE) && action.getRemoteFile().equals(remoteFile)) {
                tempRemoteFile = action.getTempRemoteFile();
                break;
            }
        }
    }
    // Download file, or throw exception
    if (tempRemoteFile != null) {
        logger.log(Level.INFO, "-> File {0} in process of being deleted; downloading corresponding temp. file {1} ...", new Object[] { remoteFile.getName(), tempRemoteFile.getName() });
        underlyingTransferManager.download(tempRemoteFile, localFile);
    } else {
        logger.log(Level.WARNING, "-> File {0} does not exist and is not in any transaction. Throwing exception.", remoteFile.getName());
        throw new StorageFileNotFoundException("File " + remoteFile.getName() + " does not exist and is not in any transaction");
    }
}
Also used : TempRemoteFile(org.syncany.plugins.transfer.files.TempRemoteFile) StorageFileNotFoundException(org.syncany.plugins.transfer.StorageFileNotFoundException) ActionTO(org.syncany.plugins.transfer.to.ActionTO) TransactionTO(org.syncany.plugins.transfer.to.TransactionTO)

Example 3 with StorageFileNotFoundException

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

the class TransactionAwareFeatureTransferManager method retrieveRemoteTransactions.

private Map<TransactionTO, TransactionRemoteFile> retrieveRemoteTransactions() throws StorageException {
    Map<String, TransactionRemoteFile> transactionFiles = list(TransactionRemoteFile.class);
    Map<TransactionTO, TransactionRemoteFile> transactions = new HashMap<TransactionTO, TransactionRemoteFile>();
    for (TransactionRemoteFile transaction : transactionFiles.values()) {
        try {
            File transactionFile = createTempFile("transaction");
            try {
                // Download transaction file
                download(transaction, transactionFile);
            } catch (StorageFileNotFoundException e) {
                // This happens if the file is deleted between listing and downloading. It is now final, so we skip it.
                logger.log(Level.INFO, "Could not find transaction file: " + transaction);
                continue;
            }
            Transformer transformer = config == null ? null : config.getTransformer();
            TransactionTO transactionTO = TransactionTO.load(transformer, transactionFile);
            // Extract final locations
            transactions.put(transactionTO, transaction);
            transactionFile.delete();
        } catch (Exception e) {
            throw new StorageException("Failed to read transactionFile", e);
        }
    }
    return transactions;
}
Also used : StorageFileNotFoundException(org.syncany.plugins.transfer.StorageFileNotFoundException) TransactionRemoteFile(org.syncany.plugins.transfer.files.TransactionRemoteFile) Transformer(org.syncany.chunk.Transformer) HashMap(java.util.HashMap) RemoteFile(org.syncany.plugins.transfer.files.RemoteFile) TempRemoteFile(org.syncany.plugins.transfer.files.TempRemoteFile) TransactionRemoteFile(org.syncany.plugins.transfer.files.TransactionRemoteFile) File(java.io.File) StorageException(org.syncany.plugins.transfer.StorageException) StorageException(org.syncany.plugins.transfer.StorageException) BlockingTransfersException(org.syncany.operations.up.BlockingTransfersException) IOException(java.io.IOException) StorageMoveException(org.syncany.plugins.transfer.StorageMoveException) StorageFileNotFoundException(org.syncany.plugins.transfer.StorageFileNotFoundException) TransactionTO(org.syncany.plugins.transfer.to.TransactionTO)

Aggregations

StorageFileNotFoundException (org.syncany.plugins.transfer.StorageFileNotFoundException)3 TempRemoteFile (org.syncany.plugins.transfer.files.TempRemoteFile)3 File (java.io.File)2 IOException (java.io.IOException)2 StorageException (org.syncany.plugins.transfer.StorageException)2 RemoteFile (org.syncany.plugins.transfer.files.RemoteFile)2 TransactionRemoteFile (org.syncany.plugins.transfer.files.TransactionRemoteFile)2 TransactionTO (org.syncany.plugins.transfer.to.TransactionTO)2 HashMap (java.util.HashMap)1 Transformer (org.syncany.chunk.Transformer)1 BlockingTransfersException (org.syncany.operations.up.BlockingTransfersException)1 StorageMoveException (org.syncany.plugins.transfer.StorageMoveException)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 SyncanyRemoteFile (org.syncany.plugins.transfer.files.SyncanyRemoteFile)1 ActionTO (org.syncany.plugins.transfer.to.ActionTO)1