Search in sources :

Example 16 with StorageException

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

the class LocalTransferManager method upload.

@Override
public void upload(File localFile, RemoteFile remoteFile) throws StorageException {
    connect();
    File repoFile = getRemoteFile(remoteFile);
    File tempRepoFile = new File(getAbsoluteParentDirectory(repoFile) + File.separator + ".temp-" + repoFile.getName());
    // Do not overwrite files with same size!
    if (repoFile.exists() && repoFile.length() == localFile.length()) {
        return;
    }
    // No such local file
    if (!localFile.exists()) {
        throw new StorageException("No such file on local disk: " + localFile);
    }
    try {
        FileUtils.copyFile(localFile, tempRepoFile);
        FileUtils.moveFile(tempRepoFile, repoFile);
    } catch (IOException ex) {
        throw new StorageException("Unable to copy file " + localFile + " to local repository " + repoFile, ex);
    }
}
Also used : 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 17 with StorageException

use of org.syncany.plugins.transfer.StorageException 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 18 with StorageException

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

the class CleanupRemoteFile method validateName.

@Override
protected String validateName(String name) throws StorageException {
    Matcher matcher = NAME_PATTERN.matcher(name);
    if (!matcher.matches()) {
        throw new StorageException(name + ": remote filename pattern does not match: " + NAME_PATTERN.pattern() + " expected.");
    }
    cleanupNumber = Long.parseLong(matcher.group(1));
    return name;
}
Also used : Matcher(java.util.regex.Matcher) StorageException(org.syncany.plugins.transfer.StorageException)

Example 19 with StorageException

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

the class PathAwareFeatureTransferManager method move.

@Override
public void move(final RemoteFile sourceFile, final RemoteFile targetFile) throws StorageException {
    final RemoteFile pathAwareSourceFile = createPathAwareRemoteFile(sourceFile);
    final RemoteFile pathAwareTargetFile = createPathAwareRemoteFile(targetFile);
    if (!createFolder(pathAwareTargetFile)) {
        throw new StorageException("Unable to create path for " + pathAwareTargetFile);
    }
    underlyingTransferManager.move(pathAwareSourceFile, pathAwareTargetFile);
    removeFolder(pathAwareSourceFile);
}
Also used : StorageException(org.syncany.plugins.transfer.StorageException) RemoteFile(org.syncany.plugins.transfer.files.RemoteFile) MultichunkRemoteFile(org.syncany.plugins.transfer.files.MultichunkRemoteFile)

Example 20 with StorageException

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

the class ReadAfterWriteConsistentFeatureTransferManager method waitForFile.

private void waitForFile(RemoteFile remoteFile) throws StorageException {
    while (true) {
        if (readAfterWriteConsistentFeatureExtension.exists(remoteFile)) {
            logger.log(Level.FINER, remoteFile + " exists on the remote side");
            throttler.reset();
            break;
        }
        try {
            long waitForMs = throttler.next();
            logger.log(Level.FINER, "File not found on the remote side, perhaps its in transit, waiting " + waitForMs + "ms ...");
            Thread.sleep(waitForMs);
        } catch (InterruptedException e) {
            throw new StorageException("Unable to wait anymore", e);
        }
    }
}
Also used : StorageException(org.syncany.plugins.transfer.StorageException)

Aggregations

StorageException (org.syncany.plugins.transfer.StorageException)33 File (java.io.File)15 MultichunkRemoteFile (org.syncany.plugins.transfer.files.MultichunkRemoteFile)14 Test (org.junit.Test)12 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)12 TestClient (org.syncany.tests.util.TestClient)11 RemoteFile (org.syncany.plugins.transfer.files.RemoteFile)10 IOException (java.io.IOException)9 Persister (org.simpleframework.xml.core.Persister)7 TempRemoteFile (org.syncany.plugins.transfer.files.TempRemoteFile)7 TransactionRemoteFile (org.syncany.plugins.transfer.files.TransactionRemoteFile)7 ActionRemoteFile (org.syncany.plugins.transfer.files.ActionRemoteFile)6 DatabaseRemoteFile (org.syncany.plugins.transfer.files.DatabaseRemoteFile)6 TransactionTO (org.syncany.plugins.transfer.to.TransactionTO)5 Matcher (java.util.regex.Matcher)4 UpOperationOptions (org.syncany.operations.up.UpOperationOptions)4 TransferManager (org.syncany.plugins.transfer.TransferManager)4 TransactionAware (org.syncany.plugins.transfer.features.TransactionAware)4 SyncanyRemoteFile (org.syncany.plugins.transfer.files.SyncanyRemoteFile)4 FilenameFilter (java.io.FilenameFilter)3