Package org.syncany.database

Examples of org.syncany.database.FileVersion


    return createFileVersion(path, type, null);
  }
 
  private FileVersion createFileVersion(String path, FileType type, FileVersion basedOnFileVersion) {
    if (basedOnFileVersion == null) {
      FileVersion fileVersion = new FileVersion();
      fileVersion.setPath(path);
      fileVersion.setType(type);
      fileVersion.setVersion(1L);
     
      return fileVersion;
    }
    else {
      FileVersion fileVersion = basedOnFileVersion.clone();
      fileVersion.setPath(path);
      fileVersion.setType(type);
      fileVersion.setVersion(basedOnFileVersion.getVersion()+1);
     
      return fileVersion;
    }     
  }   
View Full Code Here


    if (restoreFileHistoryId == null) {
      return new RestoreOperationResult(RestoreResultCode.NACK_NO_FILE);
    }
   
    // Find file version
    FileVersion restoreFileVersion = findRestoreFileVersion(restoreFileHistoryId);

    if (restoreFileVersion == null) {
      return new RestoreOperationResult(RestoreResultCode.NACK_NO_FILE);
    }
    else if (restoreFileVersion.getType() == FileType.FOLDER) {
      return new RestoreOperationResult(RestoreResultCode.NACK_INVALID_FILE);
    }

    logger.log(Level.INFO, "Restore file identified: " + restoreFileVersion);
   
View Full Code Here

    return locallyUpdatedFiles;
  }

  private void addNewDatabaseChangesToResultChanges(DatabaseVersion newDatabaseVersion, ChangeSet resultChanges) {
    for (PartialFileHistory partialFileHistory : newDatabaseVersion.getFileHistories()) {
      FileVersion lastFileVersion = partialFileHistory.getLastVersion();

      switch (lastFileVersion.getStatus()) {
      case NEW:
        resultChanges.getNewFiles().add(lastFileVersion.getPath());
        break;

      case CHANGED:
      case RENAMED:
        resultChanges.getChangedFiles().add(lastFileVersion.getPath());
        break;

      case DELETED:
        resultChanges.getDeletedFiles().add(lastFileVersion.getPath());
        break;
      }
    }
  }
View Full Code Here

   */
  private Map<FileHistoryId, FileVersion> extractMostRecentPurgeVersions(Collection<PartialFileHistory> fileHistories) {
    Map<FileHistoryId, FileVersion> mostRecentPurgeVersions = new HashMap<FileHistoryId, FileVersion>();
   
    for (PartialFileHistory fileHistory : fileHistories) {
      FileVersion mostRecentPurgeVersion = fileHistory.getLastVersion();
      mostRecentPurgeVersions.put(fileHistory.getFileHistoryId(), mostRecentPurgeVersion);
    }
   
    return mostRecentPurgeVersions;
  }
View Full Code Here

  private PartialFileHistory getFileHistoryByPathFromDatabaseVersion(DatabaseVersion databaseVersion, String path) {
    // TODO [medium] Extremely performance intensive, because this is called inside a loop above. Implement better caching for database version!!!

    for (PartialFileHistory fileHistory : databaseVersion.getFileHistories()) {
      FileVersion lastVersion = fileHistory.getLastVersion();

      if (lastVersion.getStatus() != FileStatus.DELETED && lastVersion.getPath().equals(path)) {
        return fileHistory;
      }
    }

    return null;
View Full Code Here

        logger.log(Level.FINEST, "- Ignoring file (locked): {0}", relativeFilePath);           
        return FileVisitResult.CONTINUE;
      }       
     
      // Check database by file path
      FileVersion expectedLastFileVersion = currentFileTree.get(relativeFilePath);
     
      if (expectedLastFileVersion != null) {       
        // Compare
        boolean forceChecksum = options != null && options.isForceChecksum();
        FileVersionComparison fileVersionComparison = fileVersionComparator.compare(expectedLastFileVersion, actualLocalFile.toFile(), forceChecksum);
View Full Code Here

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

        return new PartialFileHistory(lastFileHistory.getFileHistoryId());
      }
    }

    private FileVersion createNewFileVersion(FileVersion lastFileVersion, FileProperties fileProperties) {
      FileVersion fileVersion = null;

      // Version
      if (lastFileVersion == null) {
        fileVersion = new FileVersion();
        fileVersion.setVersion(1L);
        fileVersion.setStatus(FileStatus.NEW);
      }
      else {
        fileVersion = lastFileVersion.clone();
        fileVersion.setVersion(lastFileVersion.getVersion() + 1);
      }

      // Simple attributes
      fileVersion.setPath(fileProperties.getRelativePath());
      fileVersion.setLinkTarget(fileProperties.getLinkTarget());
      fileVersion.setType(fileProperties.getType());
      fileVersion.setSize(fileProperties.getSize());
      fileVersion.setChecksum(fileProperties.getChecksum());
      fileVersion.setLastModified(new Date(fileProperties.getLastModified()));
      fileVersion.setUpdated(new Date());

      // Permissions
      if (EnvironmentUtil.isWindows()) {
        fileVersion.setDosAttributes(fileProperties.getDosAttributes());
       
        if (fileVersion.getType() == FileType.FOLDER) {
          fileVersion.setPosixPermissions(DEFAULT_POSIX_PERMISSIONS_FOLDER);
        }
        else {
          fileVersion.setPosixPermissions(DEFAULT_POSIX_PERMISSIONS_FILE);
        }
      }
      else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
        fileVersion.setPosixPermissions(fileProperties.getPosixPermissions());
        fileVersion.setDosAttributes(DEFAULT_DOS_ATTRIBUTES);
      }

      // Status
      if (lastFileVersion != null) {
        if (fileVersion.getType() == FileType.FILE
            && FileChecksum.fileChecksumEquals(fileVersion.getChecksum(), lastFileVersion.getChecksum())) {
         
          fileVersion.setStatus(FileStatus.CHANGED);
        }
        else if (!fileVersion.getPath().equals(lastFileVersion.getPath())) {
          fileVersion.setStatus(FileStatus.RENAMED);
        }
        else {
          fileVersion.setStatus(FileStatus.CHANGED);
        }
      }

      return fileVersion;
    }
View Full Code Here

        logger.log(Level.FINER, "   * No old file history found, starting new history (path: " + fileProperties.getRelativePath() + ", "
            + fileProperties.getType() + ")");
        return null;
      }
      else {
        FileVersion lastFileVersion = lastFileHistory.getLastVersion();

        if (lastFileVersion.getStatus() != FileStatus.DELETED && lastFileVersion.getType() == fileProperties.getType()) {
          logger.log(Level.FINER,
              "   * Found old file history " + lastFileHistory.getFileHistoryId() + " (by path: " + fileProperties.getRelativePath()
                  + "), " + fileProperties.getType() + ", appending new version.");
          return lastFileHistory;
        }
View Full Code Here

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

TOP

Related Classes of org.syncany.database.FileVersion

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.