Search in sources :

Example 1 with NewFileSystemAction

use of org.syncany.operations.down.actions.NewFileSystemAction in project syncany by syncany.

the class FileSystemActionComparator method postCompareSort.

/**
	 * Fixes the case in which a folder has been swapped with a file (case 5a, see above)
	 * 
	 * New/Renamed file system actions must happen *after* the file was deleted. This method
	 * moves new/renamed actions below deleted folder actions. 
	 * 
	 * DEL  FILE     file1.jpg      
	 * NEW  FOLDER   folder1
	 * NEW  FILE     folder1/fileinfolder1.jpg                       < No Issue, but needs to be checked
	 * NEW  FILE     folder2                                         <<< Issue, because folder2 is deleted below!
	 * NEW  SYMLINK  folder1/symlinkinfolder1.jpg                    < No Issue, but needs to be checked
	 * REN  FILE     folder2/fileinfolder2.jpg -> folder1/x2.jpg
	 * REN  SYMLINK  folder2/symlinkinfolder2.jpg -> folder1/sym2
	 * DEL  FOLDER   folder2
	 *                                                               <<< New position of "NEW FILE folder2"!
	 */
public void postCompareSort(List<FileSystemAction> actions) {
    List<FileSystemAction> fixedActions = new ArrayList<FileSystemAction>(actions);
    int i = 0;
    while (i < fixedActions.size()) {
        FileSystemAction currentAction = fixedActions.get(i);
        if (currentAction instanceof DeleteFileSystemAction && currentAction.getType() == FileType.FOLDER) {
            break;
        }
        //System.out.println("testing "+currentAction);
        if ((currentAction instanceof NewFileSystemAction || currentAction instanceof RenameFileSystemAction) && (currentAction.getType() == FileType.FILE || currentAction.getType() == FileType.SYMLINK)) {
            int conflictingDeleteActionIndex = getPathConflictingWithDeleteActionIndex(currentAction, fixedActions);
            if (conflictingDeleteActionIndex >= 0) {
                logger.log(Level.INFO, "     --> match, conflict [" + i + "]: " + currentAction);
                logger.log(Level.INFO, "                    with [" + conflictingDeleteActionIndex + "]: " + fixedActions.get(conflictingDeleteActionIndex));
                fixedActions.remove(i);
                fixedActions.add(conflictingDeleteActionIndex, currentAction);
                // fix counter!
                i--;
            }
        }
        i++;
    }
    // Replace
    actions.clear();
    actions.addAll(fixedActions);
}
Also used : NewFileSystemAction(org.syncany.operations.down.actions.NewFileSystemAction) RenameFileSystemAction(org.syncany.operations.down.actions.RenameFileSystemAction) DeleteFileSystemAction(org.syncany.operations.down.actions.DeleteFileSystemAction) FileSystemAction(org.syncany.operations.down.actions.FileSystemAction) NewFileSystemAction(org.syncany.operations.down.actions.NewFileSystemAction) ArrayList(java.util.ArrayList) RenameFileSystemAction(org.syncany.operations.down.actions.RenameFileSystemAction) DeleteFileSystemAction(org.syncany.operations.down.actions.DeleteFileSystemAction)

Example 2 with NewFileSystemAction

use of org.syncany.operations.down.actions.NewFileSystemAction in project syncany by syncany.

the class FileSystemActionReconciliator method determineActionNoLocalLastVersion.

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.areEqual()) {
        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, winnersDatabase, assembler, winningLastVersion);
        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)) {
        FileSystemAction action = new DeleteFileSystemAction(config, null, winningLastVersion, winnersDatabase);
        outFileSystemActions.add(action);
        logger.log(Level.INFO, "     -> (3) New: winning version was deleted, but local exists, winning version = " + winningLastVersion + " at " + winningLastFile);
        logger.log(Level.INFO, "     -> " + action);
        changeSet.getDeletedFiles().add(winningLastVersion.getPath());
    } 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, winnersDatabase, assembler, winningLastVersion);
        outFileSystemActions.add(action);
        logger.log(Level.INFO, "     -> (7) Content changed: Winning file differs from winning version: " + winningLastVersion + " AND " + winningLastFile);
        logger.log(Level.INFO, "     -> " + action);
        changeSet.getNewFiles().add(winningLastVersion.getPath());
    }
}
Also used : NewFileSystemAction(org.syncany.operations.down.actions.NewFileSystemAction) RenameFileSystemAction(org.syncany.operations.down.actions.RenameFileSystemAction) NewFileSystemAction(org.syncany.operations.down.actions.NewFileSystemAction) ChangeFileSystemAction(org.syncany.operations.down.actions.ChangeFileSystemAction) SetAttributesFileSystemAction(org.syncany.operations.down.actions.SetAttributesFileSystemAction) FileSystemAction(org.syncany.operations.down.actions.FileSystemAction) NewSymlinkFileSystemAction(org.syncany.operations.down.actions.NewSymlinkFileSystemAction) DeleteFileSystemAction(org.syncany.operations.down.actions.DeleteFileSystemAction) SetAttributesFileSystemAction(org.syncany.operations.down.actions.SetAttributesFileSystemAction) FileVersionComparison(org.syncany.database.FileVersionComparator.FileVersionComparison) NewSymlinkFileSystemAction(org.syncany.operations.down.actions.NewSymlinkFileSystemAction) DeleteFileSystemAction(org.syncany.operations.down.actions.DeleteFileSystemAction)

Example 3 with NewFileSystemAction

use of org.syncany.operations.down.actions.NewFileSystemAction in project syncany by syncany.

the class FileSystemActionComparatorTest method testFileSystemActionComparator.

// TODO [low] write more unit tests for FileSystemActionComparator
@Test
public void testFileSystemActionComparator() throws Exception {
    // Setup
    List<FileSystemAction> actions = new ArrayList<FileSystemAction>();
    actions.add(createNewFileSystemAction("deletedfolderXX", FileType.FILE));
    actions.add(createNewFileSystemAction("newsymlink", FileType.SYMLINK));
    actions.add(createNewFileSystemAction("NEWfolder", FileType.FOLDER));
    actions.add(createNewFileSystemAction("newfile.jpg", FileType.FILE));
    // << same as folder above!
    actions.add(createDeleteFileSystemAction("deletedfolderXX", FileType.FOLDER));
    actions.add(createDeleteFileSystemAction("deletedsymlink.jpg", FileType.SYMLINK));
    actions.add(createNewFileSystemAction("newfile2.jpg", FileType.FILE));
    actions.add(createRenameFileSystemAction("from.jpg", "to.jpg", FileType.FILE));
    actions.add(createDeleteFileSystemAction("deletedfile2.jpg", FileType.FILE));
    // Run
    FileSystemActionComparator actionComparator = new FileSystemActionComparator();
    actionComparator.sort(actions);
    // Test
    assertArrayEquals("Actions should match order", new String[] { "DeleteFileSystemAction,deletedfile2.jpg,FILE", "DeleteFileSystemAction,deletedsymlink.jpg,SYMLINK", "NewFileSystemAction,NEWfolder,FOLDER", "NewFileSystemAction,newfile.jpg,FILE", "NewFileSystemAction,newfile2.jpg,FILE", "NewFileSystemAction,newsymlink,SYMLINK", "RenameFileSystemAction,to.jpg,FILE", "DeleteFileSystemAction,deletedfolderXX,FOLDER", // <<< moved here by postCompareSort!						
    "NewFileSystemAction,deletedfolderXX,FILE" }, toArray(actions));
    System.out.println(actions);
}
Also used : RenameFileSystemAction(org.syncany.operations.down.actions.RenameFileSystemAction) FileSystemAction(org.syncany.operations.down.actions.FileSystemAction) NewFileSystemAction(org.syncany.operations.down.actions.NewFileSystemAction) DeleteFileSystemAction(org.syncany.operations.down.actions.DeleteFileSystemAction) ArrayList(java.util.ArrayList) FileSystemActionComparator(org.syncany.operations.down.FileSystemActionComparator) Test(org.junit.Test)

Aggregations

DeleteFileSystemAction (org.syncany.operations.down.actions.DeleteFileSystemAction)3 FileSystemAction (org.syncany.operations.down.actions.FileSystemAction)3 NewFileSystemAction (org.syncany.operations.down.actions.NewFileSystemAction)3 RenameFileSystemAction (org.syncany.operations.down.actions.RenameFileSystemAction)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)1 FileVersionComparison (org.syncany.database.FileVersionComparator.FileVersionComparison)1 FileSystemActionComparator (org.syncany.operations.down.FileSystemActionComparator)1 ChangeFileSystemAction (org.syncany.operations.down.actions.ChangeFileSystemAction)1 NewSymlinkFileSystemAction (org.syncany.operations.down.actions.NewSymlinkFileSystemAction)1 SetAttributesFileSystemAction (org.syncany.operations.down.actions.SetAttributesFileSystemAction)1