use of org.syncany.plugins.transfer.StorageException in project syncany by syncany.
the class LocalTransferManager method list.
@Override
public <T extends RemoteFile> Map<String, T> list(Class<T> remoteFileClass) throws StorageException {
connect();
Path folder = Paths.get(getRemoteFilePath(remoteFileClass));
Map<String, T> files = Maps.newHashMap();
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(folder)) {
for (Path path : directoryStream) {
try {
T remoteFile = RemoteFile.createRemoteFile(path.getFileName().toString(), remoteFileClass);
files.put(path.getFileName().toString(), remoteFile);
} catch (StorageException e) {
logger.log(Level.INFO, "Cannot create instance of " + remoteFileClass.getSimpleName() + " for file " + path + "; maybe invalid file name pattern. Ignoring file.");
}
}
} catch (IOException e) {
logger.log(Level.SEVERE, "Unable to list directory", e);
}
return files;
}
use of org.syncany.plugins.transfer.StorageException in project syncany by syncany.
the class PathAwareFeatureTransferManager method list.
private <T extends RemoteFile> void list(String remoteFilePath, Map<String, T> remoteFiles, Class<T> remoteFileClass) throws StorageException {
logger.log(Level.INFO, "Listing folder for files matching " + remoteFileClass.getSimpleName() + ": " + remoteFilePath);
Map<String, FileType> folderList = pathAwareFeatureExtension.listFolder(remoteFilePath);
for (Map.Entry<String, FileType> folderListEntry : folderList.entrySet()) {
String fileName = folderListEntry.getKey();
FileType fileType = folderListEntry.getValue();
if (fileType == FileType.FILE) {
try {
remoteFiles.put(fileName, RemoteFile.createRemoteFile(fileName, remoteFileClass));
logger.log(Level.INFO, "- File: " + fileName);
} catch (StorageException e) {
// We don't care and ignore non-matching files!
}
} else if (fileType == FileType.FOLDER) {
logger.log(Level.INFO, "- Folder: " + fileName);
String newRemoteFilePath = remoteFilePath + folderSeparator + fileName;
list(newRemoteFilePath, remoteFiles, remoteFileClass);
}
}
}
use of org.syncany.plugins.transfer.StorageException 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.StorageException in project syncany by syncany.
the class AbstractInitCommand method askPluginSettings.
private TransferSettings askPluginSettings(TransferSettings settings, Map<String, String> knownPluginSettings) throws StorageException {
if (isInteractive) {
out.println();
out.println("Connection details for " + settings.getType() + " connection:");
} else {
logger.log(Level.INFO, "Non interactive mode");
}
try {
// Show OAuth output
printOAuthInformation(settings);
// Ask for plugin settings
List<TransferPluginOption> pluginOptions = TransferPluginOptions.getOrderedOptions(settings.getClass());
for (TransferPluginOption option : pluginOptions) {
askPluginSettings(settings, option, knownPluginSettings, "");
}
} catch (NoSuchFieldException e) {
logger.log(Level.SEVERE, "No token could be found, maybe user denied access", e);
throw new StorageException("No token found. Did you accept the authorization?", e);
} catch (TimeoutException e) {
logger.log(Level.SEVERE, "No token was received in the given time interval", e);
throw new StorageException("No token was received in the given time interval", e);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException | IOException | InterruptedException | ExecutionException e) {
logger.log(Level.SEVERE, "Unable to execute option generator", e);
throw new RuntimeException("Unable to execute option generator: " + e.getMessage());
}
if (!settings.isValid()) {
if (askRetryInvalidSettings(settings.getReasonForLastValidationFail())) {
return askPluginSettings(settings, knownPluginSettings);
}
throw new StorageException("Validation failed: " + settings.getReasonForLastValidationFail());
}
logger.log(Level.INFO, "Settings are " + settings.toString());
return settings;
}
use of org.syncany.plugins.transfer.StorageException in project syncany by syncany.
the class AbstractInitCommand method doOAuthInRedirectMode.
private void doOAuthInRedirectMode(OAuthGenerator generator, OAuth settings) throws IOException, InterruptedException, ExecutionException, TimeoutException, StorageException {
OAuthTokenWebListener.Builder tokenListerBuilder = OAuthTokenWebListener.forMode(settings.mode());
if (settings.callbackPort() != OAuth.RANDOM_PORT) {
tokenListerBuilder.setPort(settings.callbackPort());
}
if (!settings.callbackId().equals(OAuth.PLUGIN_ID)) {
tokenListerBuilder.setId(settings.callbackId());
}
// non standard plugin?
if (generator instanceof OAuthGenerator.WithInterceptor) {
tokenListerBuilder.setTokenInterceptor(((OAuthGenerator.WithInterceptor) generator).getInterceptor());
}
if (generator instanceof OAuthGenerator.WithExtractor) {
tokenListerBuilder.setTokenExtractor(((OAuthGenerator.WithExtractor) generator).getExtractor());
}
OAuthTokenWebListener tokenListener = tokenListerBuilder.build();
URI oAuthURL = generator.generateAuthUrl(tokenListener.start());
Future<OAuthTokenFinish> futureTokenResponse = tokenListener.getToken();
out.println();
out.println("This plugin needs you to authenticate your account so that Syncany can access it.");
out.printf("Please navigate to the URL below and accept the given permissions:\n\n %s\n\n", oAuthURL.toString());
out.print("Waiting for authorization...");
OAuthTokenFinish tokenResponse = futureTokenResponse.get(OAUTH_TOKEN_WAIT_TIMEOUT, TimeUnit.SECONDS);
if (tokenResponse != null) {
out.printf(" received token '%s'\n\n", tokenResponse.getToken());
generator.checkToken(tokenResponse.getToken(), tokenResponse.getCsrfState());
} else {
out.println(" canceled");
throw new StorageException("Error while acquiring token, perhaps user denied authorization");
}
}
Aggregations