Package org.syncany.database.FileVersionComparator

Examples of org.syncany.database.FileVersionComparator.FileVersionComparison


    else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
      fileVersion.setPosixPermissions("r--rwxrw-");
    }
   
    // Run
    FileVersionComparison fileComparison = versionComparator.compare(fileVersion, somefile, null, true);
   
    // Test
    assertFalse(fileComparison.equals());
    assertTrue(CollectionUtil.containsExactly(fileComparison.getFileChanges(), FileChange.CHANGED_CHECKSUM));
   
    // Tear down
    TestConfigUtil.deleteTestLocalConfigAndData(config);
  }
View Full Code Here


    assertArrayEquals("Files are not equal: Actual file checksum ("+StringUtil.toHex(actualFileChecksum)+") and expected file checksum ("+StringUtil.toHex(expectedFileChecksum)+") do not match.", expectedFileChecksum, actualFileChecksum);
   
    FileProperties actualFileProperties = fileVersionComparator.captureFileProperties(actualFile, null, true);
    FileProperties expectedFileProperties = fileVersionComparator.captureFileProperties(expectedFile, null, true);
   
    FileVersionComparison fileVersionComparison = fileVersionComparator.compare(expectedFileProperties, actualFileProperties, true);
   
    List<FileChange> allowedChangesList = new ArrayList<FileChange>(Arrays.asList(allowedChanges));
    allowedChangesList.add(FileChange.CHANGED_PATH);
   
    if (!CollectionUtil.containsOnly(fileVersionComparison.getFileChanges(), allowedChangesList)) {
      fail("Files are not equal: Actual file differs from expected file: "+fileVersionComparison.getFileChanges());
    }   
  }
View Full Code Here

  }

  private void determineActionNoLocalLastVersion(FileVersion winningLastVersion, File winningLastFile, MemoryDatabase winnersDatabase,
      List<FileSystemAction> outFileSystemActions) throws Exception {
   
    FileVersionComparison winningFileToVersionComparison = fileVersionComparator.compare(winningLastVersion, winningLastFile, true);
   
    boolean contentChanged = winningFileToVersionComparison.getFileChanges().contains(FileChange.CHANGED_CHECKSUM)
        || winningFileToVersionComparison.getFileChanges().contains(FileChange.CHANGED_SIZE);
   
    if (winningFileToVersionComparison.equals()) {
      logger.log(Level.INFO, "     -> (1) Equals: Nothing to do, winning version equals winning file: "+winningLastVersion+" AND "+winningLastFile)
    }
    else if (winningFileToVersionComparison.getFileChanges().contains(FileChange.DELETED)) {         
      FileSystemAction action = new NewFileSystemAction(config, winningLastVersion, winnersDatabase);
      outFileSystemActions.add(action);
     
      logger.log(Level.INFO, "     -> (2) Deleted: Local file does NOT exist, but it should, winning version not known: "+winningLastVersion+" AND "+winningLastFile);
      logger.log(Level.INFO, "     -> "+action);
     
      changeSet.getNewFiles().add(winningLastVersion.getPath());
    }
    else if (winningFileToVersionComparison.getFileChanges().contains(FileChange.NEW)) {
      logger.log(Level.INFO, "     -> (3) New: winning version was deleted, but local exists: "+winningLastVersion+" AND "+winningLastFile);         
      throw new Exception("What happend here?");
    }
    else if (winningFileToVersionComparison.getFileChanges().contains(FileChange.CHANGED_LINK_TARGET)) {         
      FileSystemAction action = new NewSymlinkFileSystemAction(config, winningLastVersion, winnersDatabase);
      outFileSystemActions.add(action);

      logger.log(Level.INFO, "     -> (4) Changed link target: winning file has a different link target: "+winningLastVersion+" AND "+winningLastFile);
      logger.log(Level.INFO, "     -> "+action);
     
      changeSet.getNewFiles().add(winningLastVersion.getPath());
    }
    else if (!contentChanged && (winningFileToVersionComparison.getFileChanges().contains(FileChange.CHANGED_LAST_MOD_DATE)
        || winningFileToVersionComparison.getFileChanges().contains(FileChange.CHANGED_ATTRIBUTES))) { 
     
      FileSystemAction action = new SetAttributesFileSystemAction(config, winningLastVersion, winnersDatabase);
      outFileSystemActions.add(action);

      logger.log(Level.INFO, "     -> (5) Changed file attributes: winning file has different file attributes: "+winningLastVersion+" AND "+winningLastFile);
      logger.log(Level.INFO, "     -> "+action);
     
      changeSet.getNewFiles().add(winningLastVersion.getPath());
    }
    else if (winningFileToVersionComparison.getFileChanges().contains(FileChange.CHANGED_PATH)) {
      logger.log(Level.INFO, "     -> (6) Changed path: winning file has a different path: "+winningLastVersion+" AND "+winningLastFile);         
      throw new Exception("What happend here?");
    }
    else { // Content changed
      FileSystemAction action = new NewFileSystemAction(config, winningLastVersion, winnersDatabase);
View Full Code Here

  }
 
  private void determineActionWithLocalVersionAndLocalFileAsExpected(FileVersion winningLastVersion, File winningLastFile,
      FileVersion localLastVersion, File localLastFile, MemoryDatabase winnersDatabase, List<FileSystemAction> fileSystemActions) {
   
    FileVersionComparison winningVersionToLocalVersionComparison = fileVersionComparator.compare(winningLastVersion, localLastVersion);
   
    boolean contentChanged = winningVersionToLocalVersionComparison.getFileChanges().contains(FileChange.CHANGED_CHECKSUM)
        || winningVersionToLocalVersionComparison.getFileChanges().contains(FileChange.CHANGED_SIZE);         
   
    if (winningVersionToLocalVersionComparison.equals()) { // Local file = local version = winning version!
      logger.log(Level.INFO, "     -> (8) Equals: Nothing to do, local file equals local version equals winning version: local file = "+localLastFile+", local version = "+localLastVersion+", winning version = "+winningLastVersion);
    }
    else if (winningVersionToLocalVersionComparison.getFileChanges().contains(FileChange.DELETED)) {
      FileSystemAction action = new ChangeFileSystemAction(config, localLastVersion, winningLastVersion, winnersDatabase);
      fileSystemActions.add(action);

      logger.log(Level.INFO, "     -> (9) Content changed: Local file does not exist, but it should: local file = "+localLastFile+", local version = "+localLastVersion+", winning version = "+winningLastVersion);
      logger.log(Level.INFO, "     -> "+action);
     
      changeSet.getChangedFiles().add(winningLastVersion.getPath());
    }
    else if (winningVersionToLocalVersionComparison.getFileChanges().contains(FileChange.NEW)) {
      FileSystemAction action = new DeleteFileSystemAction(config, localLastVersion, winningLastVersion, winnersDatabase);
      fileSystemActions.add(action);
     
      logger.log(Level.INFO, "     -> (10) Local file is exists, but should not: local file = "+localLastFile+", local version = "+localLastVersion+", winning version = "+winningLastVersion);         
      logger.log(Level.INFO, "     -> "+action)
     
      changeSet.getDeletedFiles().add(winningLastVersion.getPath());
    }
    else if (winningVersionToLocalVersionComparison.getFileChanges().contains(FileChange.CHANGED_LINK_TARGET)) {         
      FileSystemAction action = new NewSymlinkFileSystemAction(config, winningLastVersion, winnersDatabase);
      fileSystemActions.add(action);

      logger.log(Level.INFO, "     -> (11) Changed link target: local file has a different link target: local file = "+localLastFile+", local version = "+localLastVersion+", winning version = "+winningLastVersion);
      logger.log(Level.INFO, "     -> "+action);
     
      changeSet.getNewFiles().add(winningLastVersion.getPath());
    }
    else if (!contentChanged && (winningVersionToLocalVersionComparison.getFileChanges().contains(FileChange.CHANGED_LAST_MOD_DATE)
        || winningVersionToLocalVersionComparison.getFileChanges().contains(FileChange.CHANGED_ATTRIBUTES)
        || winningVersionToLocalVersionComparison.getFileChanges().contains(FileChange.CHANGED_PATH))) { 
     
      FileSystemAction action = new RenameFileSystemAction(config, localLastVersion, winningLastVersion, winnersDatabase);
      fileSystemActions.add(action);

      logger.log(Level.INFO, "     -> (12) Rename / Changed file attributes: Local file has different file attributes: local file = "+localLastFile+", local version = "+localLastVersion+", winning version = "+winningLastVersion);
View Full Code Here

      FileVersion expectedLastFileVersion = currentFileTree.get(relativeFilePath);
     
      if (expectedLastFileVersion != null) {       
        // Compare
        boolean forceChecksum = options != null && options.isForceChecksum();
        FileVersionComparison fileVersionComparison = fileVersionComparator.compare(expectedLastFileVersion, actualLocalFile.toFile(), forceChecksum);
       
        if (fileVersionComparison.equals()) {
          changeSet.getUnchangedFiles().add(relativeFilePath);
        }
        else {
          changeSet.getChangedFiles().add(relativeFilePath);
        }         
View Full Code Here

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

        determineActionNoLocalLastVersion(winningLastVersion, winningLastFile, winnersDatabase, fileSystemActions);
      }
     
      // Local version found in local database
      else {
        FileVersionComparison localFileToVersionComparison = fileVersionComparator.compare(localLastVersion, localLastFile, true);
       
        // Local file on disk as expected
        if (localFileToVersionComparison.equals()) {
          determineActionWithLocalVersionAndLocalFileAsExpected(winningLastVersion, winningLastFile, localLastVersion, localLastFile,
              winnersDatabase, fileSystemActions);
        }
       
        // Local file NOT what was expected
View Full Code Here

  protected boolean fileAsExpected(FileVersion expectedLocalFileVersion) {
    return fileAsExpected(expectedLocalFileVersion, new FileChange[] { });
 
 
  protected boolean fileAsExpected(FileVersion expectedLocalFileVersion, FileChange... allowedFileChanges) {
    FileVersionComparison fileVersionComparison = fileChanges(expectedLocalFileVersion);
   
    if (fileVersionComparison.equals()) {
      return true;
    }
    else if (allowedFileChanges.length > 0) {
      return CollectionUtil.containsOnly(fileVersionComparison.getFileChanges(), allowedFileChanges);
    }
    else {     
      return false;
    }
  } 
View Full Code Here

    }
  } 
 
  protected FileVersionComparison fileChanges(FileVersion expectedLocalFileVersion) {
    File actualLocalFile = getAbsolutePathFile(expectedLocalFileVersion.getPath()); // TODO [medium] This does not work for 'some\file' on windows!           
    FileVersionComparison fileVersionComparison = fileVersionHelper.compare(expectedLocalFileVersion, actualLocalFile, true);
   
    return fileVersionComparison;
  }
View Full Code Here

  }
 
  @Override
  public FileSystemActionResult execute() throws Exception {
    if (fileExists(fileVersion2)) {
      FileVersionComparison fileComparison = fileChanges(fileVersion2);
     
      if (fileComparison.equals()) {
        // Nothing to do.
      }
      else if (CollectionUtil.containsOnly(fileComparison.getFileChanges(), FileChange.CHANGED_LINK_TARGET)) {
        deleteFile(fileVersion2);
        createSymlink(fileVersion2);
      }
      else {
        moveToConflictFile(fileVersion2);
View Full Code Here

TOP

Related Classes of org.syncany.database.FileVersionComparator.FileVersionComparison

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.