use of org.syncany.database.PartialFileHistory.FileHistoryId in project syncany by syncany.
the class RestoreFileScenarioTest method testRestoreDeletedFileWithTargetFile.
@Test
public void testRestoreDeletedFileWithTargetFile() throws Exception {
// Setup
File tempDir = TestFileUtil.createTempDirectoryInSystemTemp();
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
java.sql.Connection databaseConnectionA = DatabaseConnectionFactory.createConnection(clientA.getDatabaseFile(), false);
// A new/up
clientA.createNewFile("A-original");
clientA.upWithForceChecksum();
String originalFileHistoryStr = TestSqlUtil.runSqlSelect("select filehistory_id from fileversion", databaseConnectionA);
assertNotNull(originalFileHistoryStr);
FileHistoryId originalFileHistoryId = FileHistoryId.parseFileId(originalFileHistoryStr);
// A "delete"
File deletedFile = new File(tempDir, "A-original-DELETED");
FileUtils.moveFile(clientA.getLocalFile("A-original"), deletedFile);
clientA.upWithForceChecksum();
// A restore
RestoreOperationOptions operationOptions = new RestoreOperationOptions();
operationOptions.setFileHistoryId(originalFileHistoryId);
operationOptions.setFileVersion(1);
operationOptions.setRelativeTargetPath("restored-file");
clientA.restore(operationOptions);
assertTrue(clientA.getLocalFile("restored-file").exists());
assertEquals(StringUtil.toHex(TestFileUtil.createChecksum(deletedFile)), StringUtil.toHex(TestFileUtil.createChecksum(clientA.getLocalFile("restored-file"))));
assertEquals(deletedFile.lastModified(), clientA.getLocalFile("restored-file").lastModified());
assertEquals(deletedFile.length(), clientA.getLocalFile("restored-file").length());
// Tear down
clientA.deleteTestData();
TestFileUtil.deleteDirectory(tempDir);
}
use of org.syncany.database.PartialFileHistory.FileHistoryId in project syncany by syncany.
the class RestoreFileScenarioTest method testRestoreDeletedFile.
@Test
public void testRestoreDeletedFile() throws Exception {
// Setup
File tempDir = TestFileUtil.createTempDirectoryInSystemTemp();
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
java.sql.Connection databaseConnectionA = DatabaseConnectionFactory.createConnection(clientA.getDatabaseFile(), false);
// A new/up
clientA.createNewFile("A-original");
clientA.upWithForceChecksum();
String originalFileHistoryStr = TestSqlUtil.runSqlSelect("select filehistory_id from fileversion", databaseConnectionA);
assertNotNull(originalFileHistoryStr);
FileHistoryId originalFileHistoryId = FileHistoryId.parseFileId(originalFileHistoryStr);
// A "delete"
File deletedFile = new File(tempDir, "A-original-DELETED");
FileUtils.moveFile(clientA.getLocalFile("A-original"), deletedFile);
clientA.upWithForceChecksum();
// A restore
RestoreOperationOptions operationOptions = new RestoreOperationOptions();
operationOptions.setFileHistoryId(originalFileHistoryId);
operationOptions.setFileVersion(1);
clientA.restore(operationOptions);
assertTrue(clientA.getLocalFile("A-original (restored version 1)").exists());
assertEquals(StringUtil.toHex(TestFileUtil.createChecksum(deletedFile)), StringUtil.toHex(TestFileUtil.createChecksum(clientA.getLocalFile("A-original (restored version 1)"))));
assertEquals(deletedFile.lastModified(), clientA.getLocalFile("A-original (restored version 1)").lastModified());
assertEquals(deletedFile.length(), clientA.getLocalFile("A-original (restored version 1)").length());
// Tear down
clientA.deleteTestData();
TestFileUtil.deleteDirectory(tempDir);
}
use of org.syncany.database.PartialFileHistory.FileHistoryId in project syncany by syncany.
the class RestoreFileScenarioTest method testRestoreDeletedWithSubfolders.
@Test
public void testRestoreDeletedWithSubfolders() throws Exception {
// Setup
File tempDir = TestFileUtil.createTempDirectoryInSystemTemp();
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
java.sql.Connection databaseConnectionA = DatabaseConnectionFactory.createConnection(clientA.getDatabaseFile(), false);
// A new/up
clientA.createNewFolder("folder/subfolder");
clientA.createNewFile("folder/subfolder/A-original");
clientA.upWithForceChecksum();
String originalFileHistoryStr = TestSqlUtil.runSqlSelect("select filehistory_id from fileversion where path='folder/subfolder/A-original'", databaseConnectionA);
assertNotNull(originalFileHistoryStr);
FileHistoryId originalFileHistoryId = FileHistoryId.parseFileId(originalFileHistoryStr);
// A "delete"
FileUtils.deleteDirectory(clientA.getLocalFile("folder"));
clientA.upWithForceChecksum();
assertFalse(clientA.getLocalFile("folder").exists());
// A restore
RestoreOperationOptions operationOptions = new RestoreOperationOptions();
operationOptions.setFileHistoryId(originalFileHistoryId);
operationOptions.setFileVersion(1);
clientA.restore(operationOptions);
assertTrue(clientA.getLocalFile("folder/subfolder").exists());
assertTrue(clientA.getLocalFile("folder/subfolder/A-original (restored version 1)").exists());
// Tear down
clientA.deleteTestData();
TestFileUtil.deleteDirectory(tempDir);
}
use of org.syncany.database.PartialFileHistory.FileHistoryId in project syncany by syncany.
the class FileHistorySqlDao method createFileHistoriesFromResult.
protected Map<FileHistoryId, PartialFileHistory> createFileHistoriesFromResult(ResultSet resultSet) throws SQLException {
Map<FileHistoryId, PartialFileHistory> fileHistories = new HashMap<FileHistoryId, PartialFileHistory>();
PartialFileHistory fileHistory = null;
while (resultSet.next()) {
FileVersion lastFileVersion = fileVersionDao.createFileVersionFromRow(resultSet);
FileHistoryId fileHistoryId = FileHistoryId.parseFileId(resultSet.getString("filehistory_id"));
// Old history (= same filehistory identifier)
if (fileHistory != null && fileHistory.getFileHistoryId().equals(fileHistoryId)) {
// Same history!
fileHistory.addFileVersion(lastFileVersion);
} else // New history!
{
// Add the old history
if (fileHistory != null) {
fileHistories.put(fileHistory.getFileHistoryId(), fileHistory);
}
// Create a new one
fileHistory = new PartialFileHistory(fileHistoryId);
fileHistory.addFileVersion(lastFileVersion);
}
}
// Add the last history
if (fileHistory != null) {
fileHistories.put(fileHistory.getFileHistoryId(), fileHistory);
}
return fileHistories;
}
use of org.syncany.database.PartialFileHistory.FileHistoryId in project syncany by syncany.
the class FileHistorySqlDao method getFileHistoriesWithLastVersion.
public List<PartialFileHistory> getFileHistoriesWithLastVersion() {
List<PartialFileHistory> fileHistories = new ArrayList<PartialFileHistory>();
try (PreparedStatement preparedStatement = getStatement("filehistory.select.master.getFileHistoriesWithLastVersion.sql")) {
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
FileHistoryId fileHistoryId = FileHistoryId.parseFileId(resultSet.getString("filehistory_id"));
FileVersion lastFileVersion = fileVersionDao.createFileVersionFromRow(resultSet);
PartialFileHistory fileHistory = new PartialFileHistory(fileHistoryId);
fileHistory.addFileVersion(lastFileVersion);
fileHistories.add(fileHistory);
}
}
return fileHistories;
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
Aggregations