use of org.syncany.plugins.transfer.files.RemoteFile in project syncany by syncany.
the class PathAwareFeatureTransferManager method upload.
@Override
public void upload(final File localFile, final RemoteFile remoteFile) throws StorageException {
final RemoteFile pathAwareRemoteFile = createPathAwareRemoteFile(remoteFile);
if (!createFolder(pathAwareRemoteFile)) {
throw new StorageException("Unable to create path for " + pathAwareRemoteFile);
}
underlyingTransferManager.upload(localFile, pathAwareRemoteFile);
}
use of org.syncany.plugins.transfer.files.RemoteFile in project syncany by syncany.
the class AbstractTransferManagerTest method uploadDownloadListDelete.
private <T extends RemoteFile> void uploadDownloadListDelete(TransferManager transferManager, File tempFromDir, File tempToDir, Class<T> remoteFileClass, T[] remoteFiles) throws Exception {
for (RemoteFile remoteFile : remoteFiles) {
File originalLocalFile = new File(tempFromDir, remoteFile.getName());
File downloadedLocalFile = new File(tempToDir, remoteFile.getName());
TestFileUtil.createNonRandomFile(originalLocalFile, 5 * 1024);
transferManager.upload(originalLocalFile, remoteFile);
transferManager.download(remoteFile, downloadedLocalFile);
String checksumOriginalFile = StringUtil.toHex(TestFileUtil.createChecksum(originalLocalFile));
String checksumDownloadedFile = StringUtil.toHex(TestFileUtil.createChecksum(downloadedLocalFile));
assertEquals("Uploaded file differs from original file, for file " + originalLocalFile, checksumOriginalFile, checksumDownloadedFile);
}
Map<String, T> listLocalFilesAfterUpload = transferManager.list(remoteFileClass);
assertEquals(remoteFiles.length, listLocalFilesAfterUpload.size());
for (RemoteFile remoteFile : remoteFiles) {
transferManager.delete(remoteFile);
}
Map<String, T> listLocalFileAfterDelete = transferManager.list(remoteFileClass);
assertEquals(0, listLocalFileAfterDelete.size());
}
use of org.syncany.plugins.transfer.files.RemoteFile in project syncany by syncany.
the class RemoteTransaction method commit.
/**
* Commits this transaction by performing the required upload and
* delete operations. The method first moves all files to the temporary
* remote location. If no errors occur, all files are moved to their
* final location.
*
* <p>The method first writes a {@link TransactionRemoteFile} containing
* all actions to be performed and then uploads this file. Then it uploads
* new files (added by {@link #upload(File, RemoteFile) upload()} and moves
* deleted files to a temporary location (deleted by {@link #delete(RemoteFile) delete()}.
*
* <p>If this was successful, the transaction file is deleted and the
* temporary files. After deleting the transaction file, the transaction
* is successfully committed.
*/
public void commit() throws StorageException {
logger.log(Level.INFO, "Starting TX.commit() ...");
if (isEmpty()) {
logger.log(Level.INFO, "- Empty transaction, not committing anything.");
return;
}
File localTransactionFile = writeLocalTransactionFile();
TransactionRemoteFile remoteTransactionFile = uploadTransactionFile(localTransactionFile);
commit(localTransactionFile, remoteTransactionFile);
}
use of org.syncany.plugins.transfer.files.RemoteFile in project syncany by syncany.
the class RemoteTransaction method moveToFinalLocation.
/**
* This method constitutes the second step in the committing process. All files have been uploaded, and they are
* now moved to their final location.
*/
private void moveToFinalLocation() throws StorageException {
for (ActionTO action : transactionTO.getActions()) {
if (action.getType().equals(ActionType.UPLOAD)) {
RemoteFile tempRemoteFile = action.getTempRemoteFile();
RemoteFile finalRemoteFile = action.getRemoteFile();
logger.log(Level.INFO, "- Moving temp. file {0} to final location {1} ...", new Object[] { tempRemoteFile, finalRemoteFile });
transferManager.move(tempRemoteFile, finalRemoteFile);
action.setStatus(ActionStatus.DONE);
}
}
}
use of org.syncany.plugins.transfer.files.RemoteFile 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