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