Search in sources :

Example 21 with StorageException

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

Example 22 with StorageException

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

the class ActionRemoteFile method validateName.

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

Example 23 with StorageException

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

the class DatabaseRemoteFile method validateName.

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

Example 24 with StorageException

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

the class ConnectOperation method downloadFile.

protected File downloadFile(TransferManager transferManager, RemoteFile remoteFile) throws StorageException {
    try {
        File tmpRepoFile = File.createTempFile("syncanyfile", "tmp");
        transferManager.download(remoteFile, tmpRepoFile);
        return tmpRepoFile;
    } catch (Exception e) {
        throw new StorageException("Unable to connect to repository.", e);
    }
}
Also used : RemoteFile(org.syncany.plugins.transfer.files.RemoteFile) MasterRemoteFile(org.syncany.plugins.transfer.files.MasterRemoteFile) SyncanyRemoteFile(org.syncany.plugins.transfer.files.SyncanyRemoteFile) File(java.io.File) StorageException(org.syncany.plugins.transfer.StorageException) StorageException(org.syncany.plugins.transfer.StorageException) CipherException(org.syncany.crypto.CipherException)

Example 25 with StorageException

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

the class ConnectOperation method verifyRepoFile.

private void verifyRepoFile(String repoFileStr) throws StorageException {
    try {
        Serializer serializer = new Persister();
        serializer.read(RepoTO.class, repoFileStr);
    } catch (Exception e) {
        throw new StorageException("Repo file corrupt.", e);
    }
}
Also used : Persister(org.simpleframework.xml.core.Persister) StorageException(org.syncany.plugins.transfer.StorageException) StorageException(org.syncany.plugins.transfer.StorageException) CipherException(org.syncany.crypto.CipherException) Serializer(org.simpleframework.xml.Serializer)

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