Search in sources :

Example 11 with DatabaseRemoteFile

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;
}
Also used : DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) ArrayList(java.util.ArrayList)

Example 12 with DatabaseRemoteFile

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);
    }
}
Also used : DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException)

Example 13 with DatabaseRemoteFile

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);
}
Also used : CommandLineClient(org.syncany.cli.CommandLineClient) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) File(java.io.File) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) Test(org.junit.Test)

Example 14 with DatabaseRemoteFile

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);
}
Also used : CommandLineClient(org.syncany.cli.CommandLineClient) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) File(java.io.File) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) Test(org.junit.Test)

Example 15 with DatabaseRemoteFile

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.");
    }
}
Also used : LsRemoteOperationResult(org.syncany.operations.ls_remote.LsRemoteOperationResult) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) RemoteFile(org.syncany.plugins.transfer.files.RemoteFile)

Aggregations

DatabaseRemoteFile (org.syncany.plugins.transfer.files.DatabaseRemoteFile)22 File (java.io.File)11 Test (org.junit.Test)8 MultichunkRemoteFile (org.syncany.plugins.transfer.files.MultichunkRemoteFile)5 RemoteFile (org.syncany.plugins.transfer.files.RemoteFile)5 ArrayList (java.util.ArrayList)4 DatabaseVersion (org.syncany.database.DatabaseVersion)4 CleanupRemoteFile (org.syncany.plugins.transfer.files.CleanupRemoteFile)4 Connection (java.sql.Connection)3 TreeMap (java.util.TreeMap)3 Config (org.syncany.config.Config)3 ApplicationSqlDao (org.syncany.database.dao.ApplicationSqlDao)3 PreparedStatement (java.sql.PreparedStatement)2 List (java.util.List)2 CommandLineClient (org.syncany.cli.CommandLineClient)2 DatabaseVersionHeader (org.syncany.database.DatabaseVersionHeader)2 MemoryDatabase (org.syncany.database.MemoryDatabase)2 LsRemoteOperationResult (org.syncany.operations.ls_remote.LsRemoteOperationResult)2 TransferManager (org.syncany.plugins.transfer.TransferManager)2 MasterRemoteFile (org.syncany.plugins.transfer.files.MasterRemoteFile)2