use of org.syncany.database.FileVersion in project syncany by syncany.
the class RenameFileWithDiffModifiedDateScenarioTest method testChangedModifiedDate.
@Test
public void testChangedModifiedDate() throws Exception {
// Setup
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
// Run
// A, create two files with identical content and change mod. date of one of them
clientA.createNewFile("A-file1.jpg", 50 * 1024);
clientA.copyFile("A-file1.jpg", "A-file1-with-different-modified-date.jpg");
clientA.getLocalFile("A-file1.jpg").setLastModified(0);
clientA.up();
// B, down, then move BOTH files
clientB.down();
assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
clientB.moveFile("A-file1.jpg", "A-file1-moved.jpg");
clientB.moveFile("A-file1-with-different-modified-date.jpg", "A-file1-with-different-modified-date-moved.jpg");
clientB.up();
TestSqlDatabase clientDatabaseB = clientB.loadLocalDatabase();
PartialFileHistory file1Orig = clientDatabaseB.getFileHistoryWithFileVersions("A-file1-moved.jpg");
PartialFileHistory file1WithDiffLastModDate = clientDatabaseB.getFileHistoryWithFileVersions("A-file1-with-different-modified-date-moved.jpg");
assertNotNull(file1Orig);
assertNotNull(file1WithDiffLastModDate);
FileVersion fileVersion1OrigV1 = file1Orig.getFileVersion(1);
FileVersion fileVersion1OrigV2 = file1Orig.getFileVersion(2);
FileVersion fileVersion1WithDiffLastModDateV1 = file1WithDiffLastModDate.getFileVersion(1);
FileVersion fileVersion1WithDiffLastModDateV2 = file1WithDiffLastModDate.getFileVersion(2);
assertNotNull(fileVersion1OrigV1);
assertNotNull(fileVersion1OrigV2);
assertNotNull(fileVersion1WithDiffLastModDateV1);
assertNotNull(fileVersion1WithDiffLastModDateV2);
assertEquals("A-file1.jpg", fileVersion1OrigV1.getName());
assertEquals("A-file1-moved.jpg", fileVersion1OrigV2.getName());
assertEquals("A-file1-with-different-modified-date.jpg", fileVersion1WithDiffLastModDateV1.getName());
assertEquals("A-file1-with-different-modified-date-moved.jpg", fileVersion1WithDiffLastModDateV2.getName());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
use of org.syncany.database.FileVersion in project syncany by syncany.
the class DeleteFileSystemAction method execute.
/**
* Deletes a file locally and/or creates a conflicting file if the
* file does not match the expectations. There are two major cases:
*
* <p>Normal case: The file version of the to-be-deleted file is known. If the file is
* as expected, it is deleted; if not and the file exists, a conflict file is created.
*
* <p>Special case: The file version of the to-be-deleted file in unknown.
* In case to-be-deleted-file exists locally, we need to compare it to
* the local file (especially its checksum!). The {@link FileVersionComparator}
* does, however, perform a cancelling test in which {@link FileVersion}s marked as
* 'DELETED' are not compared in detail (no checksum/attribute/etc. comparisons). To
* circumvent this behavior, we pretend the file has just changed and do the comparison.
* If the to-be-deleted file and file version are equal, the local file is deleted.
* Otherwise, a conflict file is created.
*/
@Override
public FileSystemActionResult execute() throws Exception {
// Special case: locally unknown file to be deleted
if (fileVersion1 == null) {
if (fileExists(fileVersion2)) {
FileVersion pretendChangedFileVersion = fileVersion2.clone();
pretendChangedFileVersion.setStatus(FileStatus.CHANGED);
if (fileAsExpected(pretendChangedFileVersion)) {
deleteFile(fileVersion2);
} else {
moveToConflictFile(fileVersion2);
}
}
} else // Normal case: locally known file to be deleted
{
if (!fileAsExpected(fileVersion1)) {
if (fileExists(fileVersion1)) {
moveToConflictFile(fileVersion2);
}
} else {
deleteFile(fileVersion1);
}
}
return new FileSystemActionResult();
}
use of org.syncany.database.FileVersion 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.FileVersion 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);
}
}
use of org.syncany.database.FileVersion in project syncany by syncany.
the class FileHistorySqlDao method getLastVersionByFileHistoryId.
private PartialFileHistory getLastVersionByFileHistoryId(String fileHistoryId) {
try (PreparedStatement preparedStatement = getStatement("filehistory.select.master.getLastVersionByFileHistoryId.sql")) {
preparedStatement.setString(1, fileHistoryId);
preparedStatement.setString(2, fileHistoryId);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
if (resultSet.next()) {
FileVersion lastFileVersion = fileVersionDao.createFileVersionFromRow(resultSet);
FileHistoryId fileHistoryIdData = FileHistoryId.parseFileId(resultSet.getString("filehistory_id"));
PartialFileHistory fileHistory = new PartialFileHistory(fileHistoryIdData);
fileHistory.addFileVersion(lastFileVersion);
return fileHistory;
} else {
return null;
}
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
Aggregations