Search in sources :

Example 1 with FileChecksum

use of org.syncany.database.FileContent.FileChecksum 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)

Example 2 with FileChecksum

use of org.syncany.database.FileContent.FileChecksum in project syncany by syncany.

the class FileContentSqlDao method createFileContents.

private Map<FileChecksum, FileContent> createFileContents(ResultSet resultSet) throws SQLException {
    Map<FileChecksum, FileContent> fileContents = new HashMap<FileChecksum, FileContent>();
    FileChecksum currentFileChecksum = null;
    while (resultSet.next()) {
        FileChecksum fileChecksum = FileChecksum.parseFileChecksum(resultSet.getString("checksum"));
        FileContent fileContent = null;
        if (currentFileChecksum != null && currentFileChecksum.equals(fileChecksum)) {
            fileContent = fileContents.get(fileChecksum);
        } else {
            fileContent = new FileContent();
            fileContent.setChecksum(fileChecksum);
            fileContent.setSize(resultSet.getLong("size"));
        }
        ChunkChecksum chunkChecksum = ChunkChecksum.parseChunkChecksum(resultSet.getString("chunk_checksum"));
        fileContent.addChunk(chunkChecksum);
        fileContents.put(fileChecksum, fileContent);
        currentFileChecksum = fileChecksum;
    }
    return fileContents;
}
Also used : FileContent(org.syncany.database.FileContent) HashMap(java.util.HashMap) ChunkChecksum(org.syncany.database.ChunkEntry.ChunkChecksum) FileChecksum(org.syncany.database.FileContent.FileChecksum)

Example 3 with FileChecksum

use of org.syncany.database.FileContent.FileChecksum in project syncany by syncany.

the class RestoreOperation method downloadMultiChunks.

private void downloadMultiChunks(FileVersion restoreFileVersion) throws StorageException, IOException {
    Set<MultiChunkId> multiChunksToDownload = new HashSet<MultiChunkId>();
    FileChecksum restoreFileChecksum = restoreFileVersion.getChecksum();
    if (restoreFileChecksum != null) {
        multiChunksToDownload.addAll(localDatabase.getMultiChunkIds(restoreFileChecksum));
        logger.log(Level.INFO, "Downloading " + multiChunksToDownload.size() + " multichunk(s) to restore file ...");
        downloader.downloadAndDecryptMultiChunks(multiChunksToDownload);
    }
}
Also used : MultiChunkId(org.syncany.database.MultiChunkEntry.MultiChunkId) FileChecksum(org.syncany.database.FileContent.FileChecksum) HashSet(java.util.HashSet)

Example 4 with FileChecksum

use of org.syncany.database.FileContent.FileChecksum in project syncany by syncany.

the class FileVersionComparatorTest method testCompareFileVersionToFile.

@Test
public void testCompareFileVersionToFile() throws Exception {
    // Setup
    Config config = TestConfigUtil.createTestLocalConfig();
    FileVersionComparator versionComparator = new FileVersionComparator(config.getLocalDir(), config.getChunker().getChecksumAlgorithm());
    // Create File
    File somefile = new File(config.getLocalDir() + "/file1");
    Path somefilePath = Paths.get(somefile.getAbsolutePath());
    TestFileUtil.createRandomFile(somefile, 130 * 1024);
    somefile.setLastModified(1182196000);
    if (EnvironmentUtil.isWindows()) {
        Files.setAttribute(somefilePath, "dos:readonly", true);
        Files.setAttribute(somefilePath, "dos:hidden", false);
        Files.setAttribute(somefilePath, "dos:archive", true);
        Files.setAttribute(somefilePath, "dos:system", false);
    } else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
        Files.setPosixFilePermissions(somefilePath, PosixFilePermissions.fromString("r--rwxrw-"));
    }
    // Create FileVersion
    FileVersion fileVersion = new FileVersion();
    fileVersion.setVersion(100L);
    // << definitely differs
    fileVersion.setChecksum(new FileChecksum(new byte[] { 0x11, 0x22, 0x33 }));
    fileVersion.setLastModified(new Date(1182196000));
    fileVersion.setPath("file1");
    fileVersion.setSize(130 * 1024L);
    fileVersion.setLinkTarget(null);
    fileVersion.setStatus(FileStatus.NEW);
    fileVersion.setType(FileType.FILE);
    if (EnvironmentUtil.isWindows()) {
        fileVersion.setDosAttributes("r-a-");
    } else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
        fileVersion.setPosixPermissions("r--rwxrw-");
    }
    // Run
    FileVersionComparison fileComparison = versionComparator.compare(fileVersion, somefile, null, true);
    // Test
    assertFalse(fileComparison.areEqual());
    assertTrue(CollectionUtil.containsExactly(fileComparison.getFileChanges(), FileChange.CHANGED_CHECKSUM));
    // Tear down
    TestConfigUtil.deleteTestLocalConfigAndData(config);
}
Also used : Path(java.nio.file.Path) Config(org.syncany.config.Config) FileVersion(org.syncany.database.FileVersion) FileVersionComparison(org.syncany.database.FileVersionComparator.FileVersionComparison) FileVersionComparator(org.syncany.database.FileVersionComparator) File(java.io.File) FileChecksum(org.syncany.database.FileContent.FileChecksum) Date(java.util.Date) Test(org.junit.Test)

Example 5 with FileChecksum

use of org.syncany.database.FileContent.FileChecksum in project syncany by syncany.

the class FileVersionComparatorTest method testCaptureFilePropertiesFromFileVersion.

@Test
public void testCaptureFilePropertiesFromFileVersion() throws Exception {
    // Setup
    Config config = TestConfigUtil.createTestLocalConfig();
    FileVersionComparator versionComparator = new FileVersionComparator(config.getLocalDir(), config.getChunker().getChecksumAlgorithm());
    FileVersion fileVersion = new FileVersion();
    fileVersion.setVersion(3L);
    fileVersion.setChecksum(new FileChecksum(new byte[] { 0x11, 0x22, 0x33 }));
    fileVersion.setLastModified(new Date(123456789));
    fileVersion.setPath("folder/file");
    fileVersion.setSize(999 * 1024L);
    fileVersion.setLinkTarget(null);
    fileVersion.setStatus(FileStatus.CHANGED);
    fileVersion.setType(FileType.FILE);
    if (EnvironmentUtil.isWindows()) {
        fileVersion.setDosAttributes("rha-");
    } else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
        fileVersion.setPosixPermissions("rw-rw-r-x");
    }
    // Run
    FileProperties fileProperties = versionComparator.captureFileProperties(fileVersion);
    // Test
    assertEquals(new FileChecksum(new byte[] { 0x11, 0x22, 0x33 }), fileProperties.getChecksum());
    assertEquals(123456789, fileProperties.getLastModified());
    assertEquals("folder/file", fileProperties.getRelativePath());
    assertEquals(999 * 1024, fileProperties.getSize());
    assertNull(fileProperties.getLinkTarget());
    assertTrue(fileProperties.exists());
    assertEquals(FileType.FILE, fileProperties.getType());
    if (EnvironmentUtil.isWindows()) {
        DosFileAttributes dosFileAttributes = FileUtil.dosAttrsFromString(fileProperties.getDosAttributes());
        assertTrue(dosFileAttributes.isArchive());
        assertTrue(dosFileAttributes.isHidden());
        assertTrue(dosFileAttributes.isReadOnly());
        assertFalse(dosFileAttributes.isSystem());
        assertNull(fileProperties.getPosixPermissions());
    } else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
        assertEquals("rw-rw-r-x", fileProperties.getPosixPermissions());
        assertNull(fileProperties.getDosAttributes());
    }
    // Tear down
    TestConfigUtil.deleteTestLocalConfigAndData(config);
}
Also used : FileProperties(org.syncany.database.FileVersionComparator.FileProperties) Config(org.syncany.config.Config) DosFileAttributes(java.nio.file.attribute.DosFileAttributes) FileVersion(org.syncany.database.FileVersion) FileVersionComparator(org.syncany.database.FileVersionComparator) FileChecksum(org.syncany.database.FileContent.FileChecksum) Date(java.util.Date) Test(org.junit.Test)

Aggregations

FileChecksum (org.syncany.database.FileContent.FileChecksum)13 Test (org.junit.Test)6 FileVersion (org.syncany.database.FileVersion)6 Date (java.util.Date)4 DatabaseVersion (org.syncany.database.DatabaseVersion)4 FileContent (org.syncany.database.FileContent)4 Config (org.syncany.config.Config)3 ChunkChecksum (org.syncany.database.ChunkEntry.ChunkChecksum)3 MemoryDatabase (org.syncany.database.MemoryDatabase)3 PartialFileHistory (org.syncany.database.PartialFileHistory)3 FileHistoryId (org.syncany.database.PartialFileHistory.FileHistoryId)3 Path (java.nio.file.Path)2 DosFileAttributes (java.nio.file.attribute.DosFileAttributes)2 ChunkEntry (org.syncany.database.ChunkEntry)2 FileVersionComparator (org.syncany.database.FileVersionComparator)2 MultiChunkEntry (org.syncany.database.MultiChunkEntry)2 MultiChunkId (org.syncany.database.MultiChunkEntry.MultiChunkId)2 File (java.io.File)1 IOException (java.io.IOException)1 InvalidPathException (java.nio.file.InvalidPathException)1