Search in sources :

Example 11 with FileVersion

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();
}
Also used : TestClient(org.syncany.tests.util.TestClient) FileVersion(org.syncany.database.FileVersion) TestSqlDatabase(org.syncany.tests.util.TestSqlDatabase) TransferSettings(org.syncany.plugins.transfer.TransferSettings) PartialFileHistory(org.syncany.database.PartialFileHistory) Test(org.junit.Test)

Example 12 with FileVersion

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());
}
Also used : FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) FileVersion(org.syncany.database.FileVersion)

Example 13 with FileVersion

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;
}
Also used : FileVersion(org.syncany.database.FileVersion) PartialFileHistory(org.syncany.database.PartialFileHistory) Date(java.util.Date)

Example 14 with FileVersion

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();
        }
    }
}
Also used : FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) FileVersion(org.syncany.database.FileVersion) PreparedStatement(java.sql.PreparedStatement)

Example 15 with FileVersion

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;
}
Also used : FileVersion(org.syncany.database.FileVersion) Date(java.util.Date) FileChecksum(org.syncany.database.FileContent.FileChecksum)

Aggregations

FileVersion (org.syncany.database.FileVersion)52 PartialFileHistory (org.syncany.database.PartialFileHistory)25 FileHistoryId (org.syncany.database.PartialFileHistory.FileHistoryId)23 Test (org.junit.Test)19 DatabaseVersion (org.syncany.database.DatabaseVersion)12 ArrayList (java.util.ArrayList)10 Date (java.util.Date)10 FileChecksum (org.syncany.database.FileContent.FileChecksum)8 MemoryDatabase (org.syncany.database.MemoryDatabase)8 PreparedStatement (java.sql.PreparedStatement)7 Config (org.syncany.config.Config)7 File (java.io.File)6 ResultSet (java.sql.ResultSet)6 SQLException (java.sql.SQLException)5 HashMap (java.util.HashMap)5 List (java.util.List)5 FileContent (org.syncany.database.FileContent)5 MultiChunkId (org.syncany.database.MultiChunkEntry.MultiChunkId)5 Connection (java.sql.Connection)4 Map (java.util.Map)4