Package org.syncany.database.FileContent

Examples of org.syncany.database.FileContent.FileChecksum


    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());
View Full Code Here


   
    // Create FileVersion
    FileVersion fileVersion = new FileVersion();
    fileVersion.setVersion(100L);

    fileVersion.setChecksum(new FileChecksum(new byte[] { 0x11, 0x22, 0x33 })); // << definitely differs
    fileVersion.setLastModified(new Date(1182196000));
    fileVersion.setPath("file1");
    fileVersion.setSize(130*1024L);
    fileVersion.setLinkTarget(null);
    fileVersion.setStatus(FileStatus.NEW);
 
View Full Code Here

    // 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);

    assertNotNull(database.getFileHistories(new FileChecksum(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 })));
    assertEquals(1, database.getFileHistories(new FileChecksum(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 })).size());

    // 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);
    fileVersion11.setChecksum(new FileChecksum(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 })); // same checksum!
    fileVersion11.setStatus(FileStatus.RENAMED);

    FileHistoryId idFile11 = FileHistoryId.parseFileId("1111111111111111");
    PartialFileHistory fileHistory11 = new PartialFileHistory(idFile11); // same ID as above

    fileHistory11.addFileVersion(fileVersion11);
    databaseVersion2.addFileHistory(fileHistory11);

    // - history 2, version 1
    FileVersion fileVersion2 = TestDatabaseUtil.createFileVersion("samechecksum2.jpg");
    fileVersion2.setChecksum(new FileChecksum(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 })); // same checksum!

    FileHistoryId idFile2 = FileHistoryId.parseFileId("1111111122222222"); // different ID
    PartialFileHistory fileHistory2 = new PartialFileHistory(idFile2);

    fileHistory2.addFileVersion(fileVersion2);
    databaseVersion2.addFileHistory(fileHistory2);

    // - history 3, version 1
    FileVersion fileVersion3 = TestDatabaseUtil.createFileVersion("samechecksum3.jpg");
    fileVersion3.setChecksum(new FileChecksum(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 })); // same checksum!

    FileHistoryId idFile3 = FileHistoryId.parseFileId("aaaaaaaa22222222"); // different ID
    PartialFileHistory fileHistory3 = new PartialFileHistory(idFile3); // different ID

    fileHistory3.addFileVersion(fileVersion3);
    databaseVersion2.addFileHistory(fileHistory3);

    database.addDatabaseVersion(databaseVersion2);

    assertNotNull(database.getFileHistories(new FileChecksum(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 })));
    assertEquals(3, database.getFileHistories(new FileChecksum(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 })).size());
  }
View Full Code Here

    // 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);
    fileVersion11.setChecksum(new FileChecksum(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 })); // same checksum!
    fileVersion11.setStatus(FileStatus.RENAMED);

    FileHistoryId idFile11 = FileHistoryId.parseFileId("1111111111111111"); // same ID
    PartialFileHistory fileHistory11 = new PartialFileHistory(idFile11);
View Full Code Here

    }
  }
 
  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)
      }
View Full Code Here

  // TODO [medium] Very inefficient. Always updates whole cache
  private void updateContentChecksumCache() {
    contentChecksumFileHistoriesCache.clear();
   
    for (PartialFileHistory fullFileHistory : fullDatabaseVersionCache.getFileHistories()) {
      FileChecksum lastVersionChecksum = fullFileHistory.getLastVersion().getChecksum();
     
      if (lastVersionChecksum != null) {
        List<PartialFileHistory> historiesWithVersionsWithSameChecksum = contentChecksumFileHistoriesCache.get(lastVersionChecksum);
       
        // Create if it does not exist
View Full Code Here

    }
  }

  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 ...");
View Full Code Here

      }
      else {
        if (fileProperties.type == FileType.FILE && forceChecksum) {
          try {
            if (fileProperties.size > 0) {
              fileProperties.checksum = new FileChecksum(FileUtil.createChecksum(file, checksumAlgorithm));
            }
            else {
              fileProperties.checksum = null;
            }
          }
View Full Code Here

    @Override
    public void onFileEnd(File file, byte[] rawFileChecksum) {
      // Get file attributes (get them while file exists)
      // Note: Do NOT move any File-methods (file.anything()) below the file.exists()-part,
      // because the file could vanish!
      FileChecksum fileChecksum = (rawFileChecksum != null) ? new FileChecksum(rawFileChecksum) : null;
      endFileProperties = fileVersionComparator.captureFileProperties(file, fileChecksum, false);

      // Check if file has vanished
      boolean fileIsLocked = endFileProperties.isLocked();
      boolean fileVanished = !endFileProperties.exists();
View Full Code Here

  private Map<FileChecksum, List<PartialFileHistory>> fillFileChecksumCache(List<PartialFileHistory> fileHistoriesWithLastVersion) {
    Map<FileChecksum, List<PartialFileHistory>> fileChecksumCache = new HashMap<FileChecksum, List<PartialFileHistory>>();

    for (PartialFileHistory fileHistory : fileHistoriesWithLastVersion) {
      FileChecksum fileChecksum = fileHistory.getLastVersion().getChecksum();

      if (fileChecksum != null) {
        List<PartialFileHistory> fileHistoriesWithSameChecksum = fileChecksumCache.get(fileChecksum);

        if (fileHistoriesWithSameChecksum == null) {
View Full Code Here

TOP

Related Classes of org.syncany.database.FileContent.FileChecksum

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.