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