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;
}
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;
}
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);
}
}
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);
}
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);
}
Aggregations