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 RestoreOperation method execute.
@Override
public RestoreOperationResult execute() throws Exception {
logger.log(Level.INFO, "");
logger.log(Level.INFO, "Running 'Restore' at client " + config.getMachineName() + " ...");
logger.log(Level.INFO, "--------------------------------------------");
// Find file history
FileHistoryId restoreFileHistoryId = findFileHistoryId();
if (restoreFileHistoryId == null) {
return new RestoreOperationResult(RestoreResultCode.NACK_NO_FILE);
}
// Find file version
FileVersion restoreFileVersion = findRestoreFileVersion(restoreFileHistoryId);
if (restoreFileVersion == null) {
return new RestoreOperationResult(RestoreResultCode.NACK_NO_FILE);
} else if (restoreFileVersion.getType() == FileType.FOLDER) {
return new RestoreOperationResult(RestoreResultCode.NACK_INVALID_FILE);
}
logger.log(Level.INFO, "Restore file identified: " + restoreFileVersion);
// Download multichunks
downloadMultiChunks(restoreFileVersion);
// Restore file
logger.log(Level.INFO, "- Restoring: " + restoreFileVersion);
RestoreFileSystemAction restoreAction = new RestoreFileSystemAction(config, assembler, restoreFileVersion, options.getRelativeTargetPath());
RestoreFileSystemActionResult restoreResult = restoreAction.execute();
return new RestoreOperationResult(RestoreResultCode.ACK, restoreResult.getTargetFile());
}
use of org.syncany.database.FileVersion in project syncany by syncany.
the class Indexer method createFileHistoryForDeletion.
private PartialFileHistory createFileHistoryForDeletion(PartialFileHistory fileHistory, FileVersion lastLocalVersion) {
PartialFileHistory deletedFileHistory = new PartialFileHistory(fileHistory.getFileHistoryId());
FileVersion deletedVersion = lastLocalVersion.clone();
deletedVersion.setStatus(FileStatus.DELETED);
deletedVersion.setVersion(fileHistory.getLastVersion().getVersion() + 1);
deletedVersion.setUpdated(new Date());
deletedFileHistory.addFileVersion(deletedVersion);
return deletedFileHistory;
}
use of org.syncany.database.FileVersion in project syncany by syncany.
the class FileVersionSqlDao method removeSpecificFileVersions.
public void removeSpecificFileVersions(Map<FileHistoryId, List<FileVersion>> purgeFileVersions) throws SQLException {
if (purgeFileVersions.size() > 0) {
try (PreparedStatement preparedStatement = getStatement(connection, "fileversion.delete.all.removeSpecificFileVersionsByIds.sql")) {
for (FileHistoryId purgeFileHistoryId : purgeFileVersions.keySet()) {
for (FileVersion purgeFileVersion : purgeFileVersions.get(purgeFileHistoryId)) {
preparedStatement.setString(1, purgeFileHistoryId.toString());
preparedStatement.setLong(2, purgeFileVersion.getVersion());
preparedStatement.addBatch();
}
}
preparedStatement.executeBatch();
}
}
}
use of org.syncany.database.FileVersion in project syncany by syncany.
the class FileVersionSqlDao method createFileVersionFromRow.
// TODO [low] This should be private; but it has to be public for a test
public FileVersion createFileVersionFromRow(ResultSet resultSet) throws SQLException {
FileVersion fileVersion = new FileVersion();
fileVersion.setFileHistoryId(FileHistoryId.parseFileId(resultSet.getString("filehistory_id")));
fileVersion.setVersion(resultSet.getLong("version"));
fileVersion.setPath(resultSet.getString("path"));
fileVersion.setType(FileType.valueOf(resultSet.getString("type")));
fileVersion.setStatus(FileStatus.valueOf(resultSet.getString("status")));
fileVersion.setSize(resultSet.getLong("size"));
fileVersion.setLastModified(new Date(resultSet.getTimestamp("lastmodified").getTime()));
if (resultSet.getString("linktarget") != null) {
fileVersion.setLinkTarget(resultSet.getString("linktarget"));
}
if (resultSet.getString("filecontent_checksum") != null) {
FileChecksum fileChecksum = FileChecksum.parseFileChecksum(resultSet.getString("filecontent_checksum"));
fileVersion.setChecksum(fileChecksum);
}
if (resultSet.getString("updated") != null) {
fileVersion.setUpdated(new Date(resultSet.getTimestamp("updated").getTime()));
}
if (resultSet.getString("posixperms") != null) {
fileVersion.setPosixPermissions(resultSet.getString("posixperms"));
}
if (resultSet.getString("dosattrs") != null) {
fileVersion.setDosAttributes(resultSet.getString("dosattrs"));
}
return fileVersion;
}
Aggregations