Package org.syncany.database

Examples of org.syncany.database.FileVersionComparator$FileVersionComparison


public class FileVersionComparatorTest {
  @Test
  public void testCaptureFilePropertiesFromFile() throws Exception {
    // Setup
    Config config = TestConfigUtil.createTestLocalConfig();
    FileVersionComparator versionComparator = new FileVersionComparator(config.getLocalDir(), config.getChunker().getChecksumAlgorithm());

    // Create file
    File somefile = new File(config.getLocalDir()+"/somefile");
    Path somefilePath = Paths.get(somefile.getAbsolutePath());
   
    TestFileUtil.createRandomFile(somefile, 100*1024);   
    somefile.setLastModified(1382196000);   
   
    if (EnvironmentUtil.isWindows()) {
      Files.setAttribute(somefilePath, "dos:archive", false);
      Files.setAttribute(somefilePath, "dos:hidden", false);
      Files.setAttribute(somefilePath, "dos:readonly", false);
      Files.setAttribute(somefilePath, "dos:system", false);
    }
    else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
      Files.setPosixFilePermissions(somefilePath, PosixFilePermissions.fromString("rw-rw-r-x"));
    }
   
    // Run
    FileProperties fileProperties = versionComparator.captureFileProperties(somefile, null, true);
   
    // Test
    assertNotNull(fileProperties.getChecksum());
    assertEquals(1382196000, fileProperties.getLastModified());
    assertEquals("somefile", fileProperties.getRelativePath());
View Full Code Here


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

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

    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);
    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.equals());
    assertTrue(CollectionUtil.containsExactly(fileComparison.getFileChanges(), FileChange.CHANGED_CHECKSUM));
   
View Full Code Here

   
    assertNotNull("Files are not equal: Actual file is "+actualFile+", expected file is null.", expectedFile);
    assertNotNull("Files are not equal: Expected file is "+expectedFile+", actual file is null.", actualFile);
   
    Path root = Paths.get(actualFile.getAbsolutePath()).getRoot();
    FileVersionComparator fileVersionComparator = new FileVersionComparator(root.toFile(), "SHA1");
   
    if (!FileUtil.exists(expectedFile)) {
      fail("Files are not equal: Expected file "+expectedFile+" does not exist.");
    }
   
    if (!FileUtil.exists(actualFile)) {
      fail("Files are not equal: Actual file "+actualFile+" does not exist.");
    }

    if (FileUtil.isSymlink(actualFile) && FileUtil.isSymlink(expectedFile)) {
      return;
    }
   
    if (actualFile.isDirectory() != expectedFile.isDirectory()) {
      fail("Files are not equal: Comparing a directory with a file (actual is dir = "+actualFile.isDirectory()+", expected is dir = "+expectedFile.isDirectory()+")");
    }
   
    if (actualFile.isDirectory() && expectedFile.isDirectory()) {
      return;
    }
   
    if (actualFile.length() != expectedFile.length()) {
      fail("Files are not equal: Actual file size ("+actualFile+" = "+actualFile.length()+") does not match expected file size ("+expectedFile+" = "+expectedFile.length()+")");
    }
   
    byte[] expectedFileChecksum = TestFileUtil.createChecksum(expectedFile);
    byte[] actualFileChecksum = TestFileUtil.createChecksum(actualFile);
   
    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)) {
View Full Code Here

 
 
  public StatusOperation(Config config, StatusOperationOptions options) {
    super(config);   
   
    this.fileVersionComparator = new FileVersionComparator(config.getLocalDir(), config.getChunker().getChecksumAlgorithm());
    this.localDatabase = new SqlDatabase(config);
    this.options = options;   
   
    this.eventBus = LocalEventBus.getInstance();
 
View Full Code Here

    private FileProperties endFileProperties;

    public IndexerDeduperListener(DatabaseVersion newDatabaseVersion, Map<FileChecksum, List<PartialFileHistory>> fileChecksumCache,
        Map<String, PartialFileHistory> filePathCache) {

      this.fileVersionComparator = new FileVersionComparator(config.getLocalDir(), config.getChunker().getChecksumAlgorithm());
      this.secureRandom = new SecureRandom();
      this.newDatabaseVersion = newDatabaseVersion;

      this.fileChecksumCache = fileChecksumCache;
      this.filePathCache = filePathCache;
View Full Code Here

 
  public FileSystemActionReconciliator(Config config, ChangeSet changeSet) {
    this.config = config;
    this.changeSet = changeSet;
    this.localDatabase = new SqlDatabase(config);
    this.fileVersionComparator = new FileVersionComparator(config.getLocalDir(), config.getChunker().getChecksumAlgorithm());
  }
View Full Code Here

  public FileSystemAction(Config config, MemoryDatabase winningDatabase, FileVersion file1, FileVersion file2) {
    this.config = config;
    this.winningDatabase = winningDatabase;
    this.fileVersion1 = file1;
    this.fileVersion2 = file2;
    this.fileVersionHelper = new FileVersionComparator(config.getLocalDir(), config.getChunker().getChecksumAlgorithm());
  }
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.