Search in sources :

Example 1 with FileSystemAction

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

the class ApplyChangesOperation method applyFileSystemActions.

/**
	 * Applies the given file system actions in a sensible order. To do that, 
	 * the given actions are first sorted using the {@link FileSystemActionComparator} and
	 * then executed individually using {@link FileSystemAction#execute()}.
	 */
private void applyFileSystemActions(List<FileSystemAction> actions) throws Exception {
    // Sort
    FileSystemActionComparator actionComparator = new FileSystemActionComparator();
    actionComparator.sort(actions);
    logger.log(Level.FINER, "- Applying file system actions (sorted!) ...");
    // Apply
    for (FileSystemAction action : actions) {
        if (logger.isLoggable(Level.FINER)) {
            logger.log(Level.FINER, "   +  {0}", action);
        }
        // Execute the file system action
        // Note that exceptions are not caught here, to prevent 
        // apply-failed-delete-on-up situations.
        action.execute();
    }
}
Also used : FileSystemAction(org.syncany.operations.down.actions.FileSystemAction) FileCreatingFileSystemAction(org.syncany.operations.down.actions.FileCreatingFileSystemAction)

Example 2 with FileSystemAction

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

the class FileSystemActionComparator method sort.

public void sort(List<FileSystemAction> actions) {
    Collections.sort(actions, internalComparator);
    postCompareSort(actions);
    if (logger.isLoggable(Level.INFO)) {
        logger.log(Level.INFO, "   Sorted actions:");
        for (FileSystemAction action : actions) {
            logger.log(Level.INFO, "   + " + action);
        }
    }
}
Also used : 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)

Example 3 with FileSystemAction

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

the class FileSystemActionReconciliator method determineActionWithLocalVersionAndLocalFileAsExpected.

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.areEqual()) {
        // 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, winnersDatabase, assembler, localLastVersion, winningLastVersion);
        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 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);
        logger.log(Level.INFO, "     -> " + action);
        changeSet.getChangedFiles().add(winningLastVersion.getPath());
    } else {
        // Content changed
        FileSystemAction action = new ChangeFileSystemAction(config, winnersDatabase, assembler, localLastVersion, winningLastVersion);
        fileSystemActions.add(action);
        logger.log(Level.INFO, "     -> (13) Content changed: Local file differs from winning version: local file = " + localLastFile + ", local version = " + localLastVersion + ", winning version = " + winningLastVersion);
        logger.log(Level.INFO, "     -> " + action);
        changeSet.getChangedFiles().add(winningLastVersion.getPath());
    }
}
Also used : 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) FileVersionComparison(org.syncany.database.FileVersionComparator.FileVersionComparison) ChangeFileSystemAction(org.syncany.operations.down.actions.ChangeFileSystemAction) NewSymlinkFileSystemAction(org.syncany.operations.down.actions.NewSymlinkFileSystemAction) RenameFileSystemAction(org.syncany.operations.down.actions.RenameFileSystemAction) DeleteFileSystemAction(org.syncany.operations.down.actions.DeleteFileSystemAction)

Example 4 with FileSystemAction

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

the class FileSystemActionReconciliator method determineActionWithLocalVersionAndLocalFileDiffers.

private void determineActionWithLocalVersionAndLocalFileDiffers(FileVersion winningLastVersion, File winningLastFile, FileVersion localLastVersion, File localLastFile, MemoryDatabase winnersDatabase, List<FileSystemAction> fileSystemActions, FileVersionComparison localFileToVersionComparison) {
    if (localFileToVersionComparison.getFileChanges().contains(FileChange.DELETED)) {
        boolean winningLastVersionDeleted = winningLastVersion.getStatus() == FileStatus.DELETED;
        if (!winningLastVersionDeleted) {
            FileSystemAction action = new ChangeFileSystemAction(config, winnersDatabase, assembler, localLastVersion, winningLastVersion);
            fileSystemActions.add(action);
            logger.log(Level.INFO, "     -> (14) Content changed: Local file does NOT exist, and winning version changed: local file = " + localLastFile + ", local version = " + localLastVersion + ", winning version = " + winningLastVersion);
            logger.log(Level.INFO, "     -> " + action);
            changeSet.getChangedFiles().add(winningLastVersion.getPath());
        } else {
            logger.log(Level.INFO, "     -> (15) Doing nothing: Local file does NOT exist, and winning version is marked DELETED: local file = " + localLastFile + ", local version = " + localLastVersion + ", winning version = " + winningLastVersion);
        }
    } else {
        FileSystemAction action = new ChangeFileSystemAction(config, winnersDatabase, assembler, winningLastVersion, localLastVersion);
        fileSystemActions.add(action);
        logger.log(Level.INFO, "     -> (16) Content changed: Local file differs from last version: local file = " + localLastFile + ", local version = " + localLastVersion + ", winning version = " + winningLastVersion);
        logger.log(Level.INFO, "     -> " + action);
        changeSet.getChangedFiles().add(winningLastVersion.getPath());
    }
}
Also used : 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) ChangeFileSystemAction(org.syncany.operations.down.actions.ChangeFileSystemAction)

Example 5 with FileSystemAction

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

the class FileSystemActionComparatorTest method toArray.

private String[] toArray(List<FileSystemAction> actions) {
    String[] actionStrArr = new String[actions.size()];
    for (int i = 0; i < actions.size(); i++) {
        FileSystemAction action = actions.get(i);
        actionStrArr[i] = action.getClass().getSimpleName() + "," + actions.get(i).getFile2().getPath() + "," + actions.get(i).getType();
        System.out.println("actual[" + i + "]: " + actionStrArr[i]);
    }
    return actionStrArr;
}
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)

Aggregations

FileSystemAction (org.syncany.operations.down.actions.FileSystemAction)11 DeleteFileSystemAction (org.syncany.operations.down.actions.DeleteFileSystemAction)9 NewFileSystemAction (org.syncany.operations.down.actions.NewFileSystemAction)9 RenameFileSystemAction (org.syncany.operations.down.actions.RenameFileSystemAction)9 ChangeFileSystemAction (org.syncany.operations.down.actions.ChangeFileSystemAction)5 NewSymlinkFileSystemAction (org.syncany.operations.down.actions.NewSymlinkFileSystemAction)5 SetAttributesFileSystemAction (org.syncany.operations.down.actions.SetAttributesFileSystemAction)5 ArrayList (java.util.ArrayList)3 FileVersionComparison (org.syncany.database.FileVersionComparator.FileVersionComparison)3 Test (org.junit.Test)2 FileVersion (org.syncany.database.FileVersion)2 PartialFileHistory (org.syncany.database.PartialFileHistory)2 File (java.io.File)1 Config (org.syncany.config.Config)1 DatabaseVersion (org.syncany.database.DatabaseVersion)1 MemoryDatabase (org.syncany.database.MemoryDatabase)1 FileHistoryId (org.syncany.database.PartialFileHistory.FileHistoryId)1 Assembler (org.syncany.operations.Assembler)1 DownOperationResult (org.syncany.operations.down.DownOperationResult)1 FileSystemActionComparator (org.syncany.operations.down.FileSystemActionComparator)1