Package org.syncany.database

Examples of org.syncany.database.PartialFileHistory


     *
     * <p>If there are more than one file with the same checksum (potential matches), the file
     * with the closest path is chosen.
     */
    private PartialFileHistory guessLastFileHistoryForFile(FileProperties fileProperties) {
      PartialFileHistory lastFileHistory = null;

      // a) Try finding a file history for which the last version has the same path
      lastFileHistory = filePathCache.get(fileProperties.getRelativePath());

      // b) If that fails, try finding files with a matching checksum
      if (lastFileHistory == null) {
        if (fileProperties.getChecksum() != null) {
          Collection<PartialFileHistory> fileHistoriesWithSameChecksum = fileChecksumCache.get(fileProperties.getChecksum());

          if (fileHistoriesWithSameChecksum != null && fileHistoriesWithSameChecksum.size() > 0) {
            lastFileHistory = guessLastFileHistoryForFileWithMatchingChecksum(fileProperties, fileHistoriesWithSameChecksum);

            // Remove the lastFileHistory we are basing this one on from the
            // cache, so no other history will be
            fileHistoriesWithSameChecksum.remove(lastFileHistory);

            if (fileHistoriesWithSameChecksum.isEmpty()) {
              fileChecksumCache.remove(fileProperties.getChecksum());
            }
          }
        }

        if (lastFileHistory == null) {
          logger.log(Level.FINER, "   * No old file history found, starting new history (path: " + fileProperties.getRelativePath()
              + ", checksum: " + fileProperties.getChecksum() + ")");
          return null;
        }
        else {
          logger.log(Level.FINER,
              "   * Found old file history " + lastFileHistory.getFileHistoryId() + " (by checksum: " + fileProperties.getChecksum()
                  + "), appending new version.");
          return lastFileHistory;
        }
      }
      else {
        if (fileProperties.getType() != lastFileHistory.getLastVersion().getType()) {
          logger.log(Level.FINER, "   * No old file history found, starting new history (path: " + fileProperties.getRelativePath()
              + ", checksum: " + fileProperties.getChecksum() + ")");
          return null;
        }
        else {
          logger.log(Level.FINER,
              "   * Found old file history " + lastFileHistory.getFileHistoryId() + " (by path: " + fileProperties.getRelativePath()
                  + "), appending new version.");
          return lastFileHistory;
        }
      }
    }
View Full Code Here


      }
    }

    private PartialFileHistory guessLastFileHistoryForFileWithMatchingChecksum(FileProperties fileProperties,
        Collection<PartialFileHistory> fileHistoriesWithSameChecksum) {
      PartialFileHistory lastFileHistory = null;

      // Check if they do not exist anymore --> assume it has moved!
      // We choose the best fileHistory to base on as follows:

      // 1. Ensure that it was modified at the same time and is the same size
      // 2. Check the fileHistory was deleted and the file does not actually exists
      // 3. Choose the one with the longest matching tail of the path to the new path

      for (PartialFileHistory fileHistoryWithSameChecksum : fileHistoriesWithSameChecksum) {
        FileVersion lastVersion = fileHistoryWithSameChecksum.getLastVersion();

        if (fileProperties.getLastModified() != lastVersion.getLastModified().getTime() || fileProperties.getSize() != lastVersion.getSize()) {
          continue;
        }

        File lastVersionOnLocalDisk = new File(config.getLocalDir() + File.separator + lastVersion.getPath());

        if (lastVersion.getStatus() != FileStatus.DELETED && !FileUtil.exists(lastVersionOnLocalDisk)) {
          if (lastFileHistory == null) {
            lastFileHistory = fileHistoryWithSameChecksum;
          }
          else {
            String filePath = fileProperties.getRelativePath();
            String currentPreviousPath = lastFileHistory.getLastVersion().getPath();
            String candidatePreviousPath = fileHistoryWithSameChecksum.getLastVersion().getPath();

            for (int i = 0; i < filePath.length(); i++) {
              if (!filePath.regionMatches(filePath.length() - i, candidatePreviousPath, candidatePreviousPath.length() - i, i)) {
                // The candidate no longer matches, take the current path.
View Full Code Here

      if (lastLocalVersion.getStatus() == FileStatus.DELETED) {
        continue;
      }

      // Add this file history if a new file with this name has been added (file type change)
      PartialFileHistory newFileWithSameName = getFileHistoryByPathFromDatabaseVersion(newDatabaseVersion, fileHistory.getLastVersion()
          .getPath());

      // If file has VANISHED, mark as DELETED
      if (!FileUtil.exists(lastLocalVersionOnDisk) || newFileWithSameName != null) {
        PartialFileHistory deletedFileHistory = new PartialFileHistory(fileHistory.getFileHistoryId());
        FileVersion deletedVersion = lastLocalVersion.clone();

        deletedVersion.setStatus(FileStatus.DELETED);
        deletedVersion.setVersion(fileHistory.getLastVersion().getVersion() + 1);
        deletedVersion.setUpdated(new Date());

        logger.log(Level.FINER, "  + Deleted: Adding DELETED version: {0}", deletedVersion);
        logger.log(Level.FINER, "                           based on: {0}", lastLocalVersion);

        deletedFileHistory.addFileVersion(deletedVersion);
        newDatabaseVersion.addFileHistory(deletedFileHistory);
      }
    }
  }
View Full Code Here

    DatabaseVersion purgeDatabaseVersion = new DatabaseVersion();
    purgeDatabaseVersion.setHeader(purgeDatabaseVersionHeader);

    for (Entry<FileHistoryId, FileVersion> fileHistoryEntry : mostRecentPurgeFileVersions.entrySet()) {
      PartialFileHistory purgeFileHistory = new PartialFileHistory(fileHistoryEntry.getKey());

      purgeFileHistory.addFileVersion(fileHistoryEntry.getValue());
      purgeDatabaseVersion.addFileHistory(purgeFileHistory);

      logger.log(Level.FINE, "- Pruning file history " + fileHistoryEntry.getKey() + " versions <= " + fileHistoryEntry.getValue() + " ...");
    }
View Full Code Here

      else {
        logger.log(Level.FINER, "- /File: {0} (directory/symlink/0-byte-file)", fileProperties.getRelativePath());
      }

      // 1. Determine if file already exists in database
      PartialFileHistory lastFileHistory = guessLastFileHistory(fileProperties);
      FileVersion lastFileVersion = (lastFileHistory != null) ? lastFileHistory.getLastVersion() : null;

      // 2. Create new file history/version
      PartialFileHistory fileHistory = createNewFileHistory(lastFileHistory);
      FileVersion fileVersion = createNewFileVersion(lastFileVersion, fileProperties);

      // 3. Compare new and last version
      FileProperties lastFileVersionProperties = fileVersionComparator.captureFileProperties(lastFileVersion);
      FileVersionComparison lastToNewFileVersionComparison = fileVersionComparator.compare(fileProperties, lastFileVersionProperties, true);

      boolean newVersionDiffersFromToLastVersion = !lastToNewFileVersionComparison.equals();

      if (newVersionDiffersFromToLastVersion) {
        fileHistory.addFileVersion(fileVersion);
        newDatabaseVersion.addFileHistory(fileHistory);

        logger.log(Level.INFO, "   * Added file version:    " + fileVersion);
        logger.log(Level.INFO, "     based on file version: " + lastFileVersion);
      }
View Full Code Here

        preparedStatement.setString(1, relativePath);
        preparedStatement.setString(2, FileStatus.DELETED.toString());
 
        ResultSet resultSet = preparedStatement.executeQuery();
 
        PartialFileHistory fileHistory = null;
 
        while (resultSet.next()) {
          if (fileHistory == null) {
            FileHistoryId fileHistoryId = FileHistoryId.parseFileId(resultSet.getString("filehistory_id"));
            fileHistory = new PartialFileHistory(fileHistoryId);
          }
 
          FileVersion fileVersion = fileVersionDao.createFileVersionFromRow(resultSet);
          fileHistory.addFileVersion(fileVersion);
        }
 
        return fileHistory;
      }
      catch (SQLException e) {
View Full Code Here

        try (ResultSet resultSet = preparedStatement.executeQuery()) {
          if (resultSet.next()) {
            FileHistoryId fileHistoryId = FileHistoryId.parseFileId(resultSet.getString("filehistory_id"));
            FileVersion lastFileVersion = fileVersionDao.createFileVersionFromRow(resultSet);
   
            PartialFileHistory fileHistory = new PartialFileHistory(fileHistoryId);
            fileHistory.addFileVersion(lastFileVersion);
   
            return fileHistory;
          }
        }
View Full Code Here

        multiChunk.addChunk(ChunkChecksum.parseChunkChecksum(chunkChecksumStr));
      }
      else if (elementPath.equalsIgnoreCase("/database/databaseVersions/databaseVersion/fileHistories/fileHistory")) {
        String fileHistoryIdStr = attributes.getValue("id");
        FileHistoryId fileId = FileHistoryId.parseFileId(fileHistoryIdStr);
        fileHistory = new PartialFileHistory(fileId);
      }
      else if (elementPath.equalsIgnoreCase("/database/databaseVersions/databaseVersion/fileHistories/fileHistory/fileVersions/fileVersion")) {
        String fileVersionStr = attributes.getValue("version");
        String path = attributes.getValue("path");
        String pathEncoded = attributes.getValue("pathEncoded");
View Full Code Here

   
    DatabaseVersion dirtyDatabaseVersionB = databaseVersionsDirtyListB.get(0);
    assertNotNull(dirtyDatabaseVersionB);
    assertEquals(1, dirtyDatabaseVersionB.getFileHistories().size());
   
    PartialFileHistory fileHistoryFile1B = dirtyDatabaseVersionB.getFileHistories().iterator().next();   
    assertNotNull(fileHistoryFile1B);
    assertEquals(1, fileHistoryFile1B.getFileVersions().size());
    assertEquals("A-file1.jpg", fileHistoryFile1B.getLastVersion().getPath());
       
    assertFileEquals(clientA.getLocalFile("A-file1.jpg"), clientB.getLocalFile("A-file1.jpg"));
    assertConflictingFileExists("A-file1.jpg", clientB.getLocalFilesExcludeLockedAndNoRead());   
   
    // Run (part 2)
View Full Code Here

    }
  }

  private void printNonGroupedHistories(LsOperationResult operationResult, int longestSize, int longestVersion) {
    for (FileVersion fileVersion : operationResult.getFileTree().values()) {
      PartialFileHistory fileHistory = operationResult.getFileVersions().get(fileVersion.getFileHistoryId());
     
      for (FileVersion fileVersionInHistory : fileHistory.getFileVersions().values()) {
        printOneVersion(fileVersionInHistory, longestVersion, longestSize);           
      }         
    } 
  }
View Full Code Here

TOP

Related Classes of org.syncany.database.PartialFileHistory

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.