use of org.syncany.plugins.transfer.files.DatabaseRemoteFile in project syncany by syncany.
the class LsRemoteOperation method listUnknownRemoteDatabases.
private List<DatabaseRemoteFile> listUnknownRemoteDatabases(TransferManager transferManager, List<DatabaseRemoteFile> knownDatabases) throws StorageException {
logger.log(Level.INFO, "Retrieving remote database list.");
List<DatabaseRemoteFile> unknownRemoteDatabases = new ArrayList<DatabaseRemoteFile>();
// List all remote database files
Map<String, DatabaseRemoteFile> remoteDatabaseFiles = transferManager.list(DatabaseRemoteFile.class);
for (DatabaseRemoteFile remoteDatabaseFile : remoteDatabaseFiles.values()) {
// This does NOT filter 'lock' files!
if (knownDatabases.contains(remoteDatabaseFile)) {
logger.log(Level.INFO, "- Remote database {0} is already known (in local database). Ignoring.", remoteDatabaseFile.getName());
} else {
logger.log(Level.INFO, "- Remote database {0} is new.", remoteDatabaseFile.getName());
unknownRemoteDatabases.add(remoteDatabaseFile);
}
}
return unknownRemoteDatabases;
}
use of org.syncany.plugins.transfer.files.DatabaseRemoteFile in project syncany by syncany.
the class ApplicationSqlDao method getKnownDatabases.
/**
* Queries the database for already known {@link DatabaseRemoteFile}s and returns a
* list of all of them.
*
* @return Returns a list of all known/processed remote databases
*/
public List<DatabaseRemoteFile> getKnownDatabases() {
List<DatabaseRemoteFile> knownDatabases = new ArrayList<DatabaseRemoteFile>();
try (PreparedStatement preparedStatement = getStatement("application.select.all.getKnownDatabases.sql")) {
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
String clientName = resultSet.getString("client");
int fileNumber = resultSet.getInt("filenumber");
knownDatabases.add(new DatabaseRemoteFile(clientName, fileNumber));
}
return knownDatabases;
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.syncany.plugins.transfer.files.DatabaseRemoteFile in project syncany by syncany.
the class UpCommandTest method testCliSyncUpWithCleanup.
@Test
public void testCliSyncUpWithCleanup() throws Exception {
Map<String, String> connectionSettings = TestConfigUtil.createTestLocalConnectionSettings();
Map<String, String> clientA = TestCliUtil.createLocalTestEnvAndInit("A", connectionSettings);
Map<String, String> clientB = TestCliUtil.createLocalTestEnvAndConnect("B", connectionSettings);
new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "up" }).start();
for (int i = 1; i <= 20; i++) {
new File(clientA.get("localdir") + "/somefolder" + i).mkdir();
new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "up" }).start();
}
// Delete something so that cleanup actually does something
new File(clientA.get("localdir") + "/somefolder1").delete();
new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "up" }).start();
// Apply all changes at B
new CommandLineClient(new String[] { "--localdir", clientB.get("localdir"), "down" }).start();
// Now cleanup
String[] cliOut = TestCliUtil.runAndCaptureOutput(new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "cleanup" }));
assertEquals(11, cliOut.length);
assertTrue(cliOut[8].contains("22 database files merged"));
assertTrue(cliOut[9].contains("1 file histories shortened"));
assertTrue(cliOut[10].contains("Cleanup successful"));
for (int i = 1; i <= 22; i++) {
DatabaseRemoteFile expectedDatabaseRemoteFile = new DatabaseRemoteFile("A", i);
File databaseFileInRepo = new File(connectionSettings.get("path") + "/databases/" + expectedDatabaseRemoteFile.getName());
assertFalse("Database file SHOULD NOT exist: " + databaseFileInRepo, databaseFileInRepo.exists());
}
for (int i = 23; i <= 23; i++) {
DatabaseRemoteFile expectedDatabaseRemoteFile = new DatabaseRemoteFile("A", i);
File databaseFileInRepo = new File(connectionSettings.get("path") + "/databases/" + expectedDatabaseRemoteFile.getName());
assertTrue("Database file SHOULD exist: " + databaseFileInRepo, databaseFileInRepo.exists());
}
cliOut = TestCliUtil.runAndCaptureOutput(new CommandLineClient(new String[] { "--localdir", clientB.get("localdir"), "down" }));
assertEquals(6, cliOut.length);
assertTrue(cliOut[4].contains("1 database file(s) processed"));
assertTrue(cliOut[5].contains("Sync down finished"));
TestCliUtil.deleteTestLocalConfigAndData(clientA);
TestCliUtil.deleteTestLocalConfigAndData(clientB);
}
use of org.syncany.plugins.transfer.files.DatabaseRemoteFile in project syncany by syncany.
the class UpCommandTest method testCliSyncUpWithoutCleanup.
@Test
public void testCliSyncUpWithoutCleanup() throws Exception {
Map<String, String> connectionSettings = TestConfigUtil.createTestLocalConnectionSettings();
Map<String, String> clientA = TestCliUtil.createLocalTestEnvAndInit("A", connectionSettings);
new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "up" }).start();
for (int i = 1; i <= 20; i++) {
new File(clientA.get("localdir") + "/somefolder" + i).mkdir();
new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "up" }).start();
}
for (int i = 1; i <= 20; i++) {
DatabaseRemoteFile expectedDatabaseRemoteFile = new DatabaseRemoteFile("A", i);
File databaseFileInRepo = new File(connectionSettings.get("path") + "/databases/" + expectedDatabaseRemoteFile.getName());
assertTrue("Database file SHOULD exist: " + databaseFileInRepo, databaseFileInRepo.exists());
}
TestCliUtil.deleteTestLocalConfigAndData(clientA);
}
use of org.syncany.plugins.transfer.files.DatabaseRemoteFile in project syncany by syncany.
the class LsRemoteCommand method printResults.
@Override
public void printResults(OperationResult operationResult) {
LsRemoteOperationResult concreteOperationResult = (LsRemoteOperationResult) operationResult;
List<DatabaseRemoteFile> remoteStatus = concreteOperationResult.getUnknownRemoteDatabases();
if (remoteStatus.size() > 0) {
for (RemoteFile unknownRemoteFile : remoteStatus) {
out.println("? " + unknownRemoteFile.getName());
}
} else {
out.println("No remote changes.");
}
}
Aggregations