Search in sources :

Example 11 with FileHistoryId

use of org.syncany.database.PartialFileHistory.FileHistoryId in project syncany by syncany.

the class MemoryDatabaseCacheTest method testGetFileHistory.

@Test
public void testGetFileHistory() throws IOException {
    MemoryDatabase database = new MemoryDatabase();
    // Round 1: Add file history & version
    DatabaseVersion databaseVersion1 = TestDatabaseUtil.createDatabaseVersion();
    // - history 1, version 1
    FileVersion fileVersion1 = TestDatabaseUtil.createFileVersion("samechecksum1.jpg");
    fileVersion1.setChecksum(new FileChecksum(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }));
    FileHistoryId idFile1 = FileHistoryId.parseFileId("1111111111111111");
    PartialFileHistory fileHistory1 = new PartialFileHistory(idFile1);
    fileHistory1.addFileVersion(fileVersion1);
    databaseVersion1.addFileHistory(fileHistory1);
    database.addDatabaseVersion(databaseVersion1);
    FileHistoryId idFile1Get = FileHistoryId.parseFileId("1111111111111111");
    assertNotNull(database.getFileHistory(idFile1Get));
    assertEquals(fileHistory1, database.getFileHistory(idFile1Get));
    // Round 2: Add two other versions with same checksum to new database version
    DatabaseVersion databaseVersion2 = TestDatabaseUtil.createDatabaseVersion(databaseVersion1);
    // - history 1, version 2
    FileVersion fileVersion11 = TestDatabaseUtil.createFileVersion("samechecksum2-renamed.jpg", fileVersion1);
    // same checksum!
    fileVersion11.setChecksum(new FileChecksum(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }));
    fileVersion11.setStatus(FileStatus.RENAMED);
    // same ID
    FileHistoryId idFile11 = FileHistoryId.parseFileId("1111111111111111");
    PartialFileHistory fileHistory11 = new PartialFileHistory(idFile11);
    fileHistory11.addFileVersion(fileVersion11);
    databaseVersion2.addFileHistory(fileHistory11);
    database.addDatabaseVersion(databaseVersion2);
    // same ID
    FileHistoryId idFile111 = FileHistoryId.parseFileId("1111111111111111");
    assertNotNull(database.getFileHistory(idFile111));
    assertEquals(2, database.getFileHistory(idFile111).getFileVersions().size());
}
Also used : FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) FileVersion(org.syncany.database.FileVersion) MemoryDatabase(org.syncany.database.MemoryDatabase) FileChecksum(org.syncany.database.FileContent.FileChecksum) PartialFileHistory(org.syncany.database.PartialFileHistory) DatabaseVersion(org.syncany.database.DatabaseVersion) Test(org.junit.Test)

Example 12 with FileHistoryId

use of org.syncany.database.PartialFileHistory.FileHistoryId in project syncany by syncany.

the class MemoryDatabaseCacheTest method testFilenameCache.

@Test
public void testFilenameCache() throws IOException {
    MemoryDatabase database = new MemoryDatabase();
    // Round 1: Add file history & version
    DatabaseVersion databaseVersion1 = TestDatabaseUtil.createDatabaseVersion();
    FileVersion fileVersion1 = TestDatabaseUtil.createFileVersion("file1.jpg");
    FileHistoryId idFile1 = FileHistoryId.parseFileId("1111111111111111");
    PartialFileHistory fileHistory1 = new PartialFileHistory(idFile1);
    fileHistory1.addFileVersion(fileVersion1);
    databaseVersion1.addFileHistory(fileHistory1);
    database.addDatabaseVersion(databaseVersion1);
    assertEquals(fileHistory1, database.getFileHistory("file1.jpg"));
    // Round 2: Add new version
    DatabaseVersion databaseVersion2 = TestDatabaseUtil.createDatabaseVersion(databaseVersion1);
    FileVersion fileVersion2 = TestDatabaseUtil.createFileVersion("file2.jpg", fileVersion1);
    // same ID
    FileHistoryId idFile2 = FileHistoryId.parseFileId("1111111111111111");
    PartialFileHistory fileHistory2 = new PartialFileHistory(idFile2);
    fileHistory2.addFileVersion(fileVersion2);
    databaseVersion2.addFileHistory(fileHistory2);
    database.addDatabaseVersion(databaseVersion2);
    assertNotNull(database.getFileHistory("file2.jpg"));
    assertEquals(2, database.getFileHistory("file2.jpg").getFileVersions().size());
    assertNull(database.getFileHistory("file1.jpg"));
    // Round 3: Add deleted version
    DatabaseVersion databaseVersion3 = TestDatabaseUtil.createDatabaseVersion(databaseVersion2);
    FileVersion fileVersion3 = TestDatabaseUtil.createFileVersion("file2.jpg", fileVersion2);
    fileVersion3.setStatus(FileStatus.DELETED);
    // same ID
    FileHistoryId idFile3 = FileHistoryId.parseFileId("1111111111111111");
    // same ID
    PartialFileHistory fileHistory3 = new PartialFileHistory(idFile3);
    fileHistory3.addFileVersion(fileVersion3);
    databaseVersion3.addFileHistory(fileHistory3);
    database.addDatabaseVersion(databaseVersion3);
    assertNull(database.getFileHistory("file2.jpg"));
}
Also used : FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) FileVersion(org.syncany.database.FileVersion) MemoryDatabase(org.syncany.database.MemoryDatabase) PartialFileHistory(org.syncany.database.PartialFileHistory) DatabaseVersion(org.syncany.database.DatabaseVersion) Test(org.junit.Test)

Example 13 with FileHistoryId

use of org.syncany.database.PartialFileHistory.FileHistoryId in project syncany by syncany.

the class DatabaseVersionSqlDao method createDatabaseVersionFromRow.

protected DatabaseVersion createDatabaseVersionFromRow(ResultSet resultSet, boolean excludeChunkData, int fileHistoryMaxCount) throws SQLException {
    DatabaseVersionHeader databaseVersionHeader = createDatabaseVersionHeaderFromRow(resultSet);
    DatabaseVersion databaseVersion = new DatabaseVersion();
    databaseVersion.setHeader(databaseVersionHeader);
    // Add chunk/multichunk/filecontent data
    if (!excludeChunkData) {
        Map<ChunkChecksum, ChunkEntry> chunks = chunkDao.getChunks(databaseVersionHeader.getVectorClock());
        Map<MultiChunkId, MultiChunkEntry> multiChunks = multiChunkDao.getMultiChunks(databaseVersionHeader.getVectorClock());
        Map<FileChecksum, FileContent> fileContents = fileContentDao.getFileContents(databaseVersionHeader.getVectorClock());
        for (ChunkEntry chunk : chunks.values()) {
            databaseVersion.addChunk(chunk);
        }
        for (MultiChunkEntry multiChunk : multiChunks.values()) {
            databaseVersion.addMultiChunk(multiChunk);
        }
        for (FileContent fileContent : fileContents.values()) {
            databaseVersion.addFileContent(fileContent);
        }
    }
    // Add file histories
    Map<FileHistoryId, PartialFileHistory> fileHistories = fileHistoryDao.getFileHistoriesWithFileVersions(databaseVersionHeader.getVectorClock(), fileHistoryMaxCount);
    for (PartialFileHistory fileHistory : fileHistories.values()) {
        databaseVersion.addFileHistory(fileHistory);
    }
    return databaseVersion;
}
Also used : FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) MultiChunkId(org.syncany.database.MultiChunkEntry.MultiChunkId) ChunkChecksum(org.syncany.database.ChunkEntry.ChunkChecksum) FileChecksum(org.syncany.database.FileContent.FileChecksum) PartialFileHistory(org.syncany.database.PartialFileHistory) FileContent(org.syncany.database.FileContent) ChunkEntry(org.syncany.database.ChunkEntry) MultiChunkEntry(org.syncany.database.MultiChunkEntry) DatabaseVersionHeader(org.syncany.database.DatabaseVersionHeader) MultiChunkEntry(org.syncany.database.MultiChunkEntry) DatabaseVersion(org.syncany.database.DatabaseVersion)

Example 14 with FileHistoryId

use of org.syncany.database.PartialFileHistory.FileHistoryId in project syncany by syncany.

the class RestoreCommand method parseOptions.

@Override
public RestoreOperationOptions parseOptions(String[] operationArgs) throws Exception {
    RestoreOperationOptions operationOptions = new RestoreOperationOptions();
    OptionParser parser = new OptionParser();
    parser.allowsUnrecognizedOptions();
    OptionSpec<Integer> optionRevision = parser.acceptsAll(asList("r", "revision")).withRequiredArg().ofType(Integer.class);
    OptionSpec<String> optionTarget = parser.acceptsAll(asList("t", "target")).withRequiredArg().ofType(String.class);
    OptionSet options = parser.parse(operationArgs);
    // --revision=<n>
    if (options.has(optionRevision)) {
        operationOptions.setFileVersion(options.valueOf(optionRevision));
    }
    // --target=<file>
    if (options.has(optionTarget)) {
        operationOptions.setRelativeTargetPath(options.valueOf(optionTarget));
    }
    // <file-history-id>
    List<?> nonOptionArgs = options.nonOptionArguments();
    if (nonOptionArgs.size() != 1) {
        throw new Exception("Invalid Syntax: File history ID must be specified.");
    }
    FileHistoryId restoreFileHistory = FileHistoryId.parseFileId(nonOptionArgs.get(0).toString());
    operationOptions.setFileHistoryId(restoreFileHistory);
    return operationOptions;
}
Also used : RestoreOperationOptions(org.syncany.operations.restore.RestoreOperationOptions) FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Example 15 with FileHistoryId

use of org.syncany.database.PartialFileHistory.FileHistoryId in project syncany by syncany.

the class CleanupOperation method putAllFileVersionsInMap.

private void putAllFileVersionsInMap(Map<FileHistoryId, List<FileVersion>> newFileVersions, Map<FileHistoryId, List<FileVersion>> fileHistoryPurgeFileVersions) {
    for (FileHistoryId fileHistoryId : newFileVersions.keySet()) {
        List<FileVersion> purgeFileVersions = fileHistoryPurgeFileVersions.get(fileHistoryId);
        List<FileVersion> newPurgeFileVersions = newFileVersions.get(fileHistoryId);
        if (purgeFileVersions != null) {
            purgeFileVersions.addAll(newPurgeFileVersions);
        } else {
            fileHistoryPurgeFileVersions.put(fileHistoryId, newPurgeFileVersions);
        }
    }
}
Also used : FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) FileVersion(org.syncany.database.FileVersion)

Aggregations

FileHistoryId (org.syncany.database.PartialFileHistory.FileHistoryId)28 FileVersion (org.syncany.database.FileVersion)21 PartialFileHistory (org.syncany.database.PartialFileHistory)12 Test (org.junit.Test)10 DatabaseVersion (org.syncany.database.DatabaseVersion)8 File (java.io.File)6 ArrayList (java.util.ArrayList)6 MemoryDatabase (org.syncany.database.MemoryDatabase)6 PreparedStatement (java.sql.PreparedStatement)5 ResultSet (java.sql.ResultSet)5 HashMap (java.util.HashMap)5 MultiChunkId (org.syncany.database.MultiChunkEntry.MultiChunkId)4 SQLException (java.sql.SQLException)3 List (java.util.List)3 TreeMap (java.util.TreeMap)3 ChunkChecksum (org.syncany.database.ChunkEntry.ChunkChecksum)3 FileContent (org.syncany.database.FileContent)3 FileChecksum (org.syncany.database.FileContent.FileChecksum)3 MultiChunkEntry (org.syncany.database.MultiChunkEntry)3 RestoreOperationOptions (org.syncany.operations.restore.RestoreOperationOptions)3