use of org.syncany.operations.down.DownOperationResult in project syncany by syncany.
the class RenameNoDownloadMultiChunksScenarioTest method testRenameAndCheckIfMultiChunksAreDownloaded.
@Test
public void testRenameAndCheckIfMultiChunksAreDownloaded() throws Exception {
// Setup
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
// Run
// Prepare, create file at A, sync it to B
clientA.createNewFile("A-file1");
clientA.sync();
clientB.sync();
// Now move file, and sync
clientA.moveFile("A-file1", "A-file-moved1");
clientA.up();
DownOperationResult downOperationResult = clientB.down();
assertEquals("No multichunks should have been downloaded.", 0, downOperationResult.getDownloadedMultiChunks().size());
assertTrue("Moved files should exist.", clientB.getLocalFile("A-file-moved1").exists());
assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
use of org.syncany.operations.down.DownOperationResult in project syncany by syncany.
the class FileSystemActionReconciliatorTest method testFileSystemActionReconDeleteNonExistingFolder.
@Test
public void testFileSystemActionReconDeleteNonExistingFolder() throws Exception {
// Setup
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
Config testConfigA = clientA.getConfig();
// - Create first database version
clientA.createNewFolder("new folder/some subfolder");
clientA.upWithForceChecksum();
// Delete this!
clientA.deleteFile("new folder/some subfolder");
// - Create new version (delete folder)
TestSqlDatabase sqlDatabaseA = new TestSqlDatabase(testConfigA);
PartialFileHistory folderFileHistoryWithLastVersion = sqlDatabaseA.getFileHistoryWithLastVersion("new folder/some subfolder");
FileVersion deletedFolderVersion = folderFileHistoryWithLastVersion.getLastVersion().clone();
deletedFolderVersion.setStatus(FileStatus.DELETED);
deletedFolderVersion.setVersion(deletedFolderVersion.getVersion() + 1);
PartialFileHistory deletedFolderVersionHistory = new PartialFileHistory(folderFileHistoryWithLastVersion.getFileHistoryId());
deletedFolderVersionHistory.addFileVersion(deletedFolderVersion);
DatabaseVersion winnersDatabaseVersion = TestDatabaseUtil.createDatabaseVersion(sqlDatabaseA.getLastDatabaseVersionHeader());
winnersDatabaseVersion.addFileHistory(deletedFolderVersionHistory);
// - Create memory database with this version
MemoryDatabase winnersDatabase = new MemoryDatabase();
winnersDatabase.addDatabaseVersion(winnersDatabaseVersion);
// Run! Finally!
DownOperationResult outDownOperationResult = new DownOperationResult();
FileSystemActionReconciliator fileSystemActionReconciliator = new FileSystemActionReconciliator(testConfigA, outDownOperationResult.getChangeSet());
List<FileSystemAction> fileSystemActions = fileSystemActionReconciliator.determineFileSystemActions(winnersDatabase);
assertNotNull(fileSystemActions);
assertEquals(0, fileSystemActions.size());
// Tear down
clientA.deleteTestData();
}
use of org.syncany.operations.down.DownOperationResult in project syncany by syncany.
the class DownCommand method printResults.
@Override
public void printResults(OperationResult operationResult) {
DownOperationResult concreteOperationResult = (DownOperationResult) operationResult;
if (concreteOperationResult.getResultCode() == DownResultCode.OK_WITH_REMOTE_CHANGES) {
ChangeSet changeSet = concreteOperationResult.getChangeSet();
if (changeSet.hasChanges()) {
List<String> newFiles = new ArrayList<String>(changeSet.getNewFiles());
List<String> changedFiles = new ArrayList<String>(changeSet.getChangedFiles());
List<String> deletedFiles = new ArrayList<String>(changeSet.getDeletedFiles());
Collections.sort(newFiles);
Collections.sort(changedFiles);
Collections.sort(deletedFiles);
for (String newFile : newFiles) {
out.println("A " + newFile);
}
for (String changedFile : changedFiles) {
out.println("M " + changedFile);
}
for (String deletedFile : deletedFiles) {
out.println("D " + deletedFile);
}
} else {
out.println(concreteOperationResult.getDownloadedUnknownDatabases().size() + " database file(s) processed.");
}
out.println("Sync down finished.");
} else {
out.println("Sync down skipped, no remote changes.");
}
}
use of org.syncany.operations.down.DownOperationResult in project syncany by syncany.
the class DownCommand method execute.
@Override
public int execute(String[] operationArgs) throws Exception {
DownOperationOptions operationOptions = parseOptions(operationArgs);
DownOperationResult operationResult = new DownOperation(config, operationOptions).execute();
printResults(operationResult);
return 0;
}
use of org.syncany.operations.down.DownOperationResult in project syncany by syncany.
the class WatchOperation method runSync.
/**
* Runs one iteration of the main synchronization loop, containing a {@link DownOperation},
* an {@link UpOperation} and (if required), a {@link CleanupOperation}.
*/
private void runSync() throws Exception {
if (!syncRunning.get()) {
syncRunning.set(true);
syncRequested.set(false);
logger.log(Level.INFO, "RUNNING SYNC ...");
fireStartEvent();
try {
boolean notifyChanges = false;
// Run down
DownOperationResult downResult = new DownOperation(config, options.getDownOptions()).execute();
if (downResult.getResultCode() == DownResultCode.OK_WITH_REMOTE_CHANGES) {
// TODO [low] Do something?
}
// Run up
UpOperationResult upOperationResult = new UpOperation(config, options.getUpOptions()).execute();
if (upOperationResult.getResultCode() == UpResultCode.OK_CHANGES_UPLOADED && upOperationResult.getChangeSet().hasChanges()) {
upCount.incrementAndGet();
notifyChanges = true;
}
CleanupOperationResult cleanupOperationResult = new CleanupOperation(config, options.getCleanupOptions()).execute();
if (cleanupOperationResult.getResultCode() == CleanupResultCode.OK) {
notifyChanges = true;
}
// Fire change event if up and/or cleanup
if (notifyChanges) {
notifyChanges();
}
} finally {
logger.log(Level.INFO, "SYNC DONE.");
syncRunning.set(false);
fireEndEvent();
}
} else {
// Can't do a log message here, because this bit is called thousand
// of times when file system events occur.
syncRequested.set(true);
}
}
Aggregations