lib/delta/delta.js
function resolveFileConflicts(node, callback) {
  var rActions = node.remoteActions;
  var lActions = node.localActions;

  if(!rActions || !lActions) {
    //only one side changed, no conflicts
    return callback(null);
  }

  if(rActions.create && lActions.create) {
    //on both sides created or updated
    var currentLocalPath = utility.joinPath(node.parent, node.name);

    var localHash, stat;
    try {
      localHash = fsWrap.md5FileSync(currentLocalPath);
      stat = fsWrap.lstatSync(currentLocalPath);
    } catch(e) {
      logger.warning('resolveFileConflicts failed', {category: 'sync-delta', node, err: e});

      var err = new BlnDeltaError(e.message);
      throw err;
    }

    if(rActions.create.hash && rActions.create.hash === localHash && rActions.create.size === stat.size) {
      delete node.remoteActions;
      delete node.localActions;

      node.hash = localHash;
      node.version = rActions.create.version;
      node.size = stat.size;
      node.mtime = stat.mtime;
      node.ctime = stat.ctime;

      node.remoteId = rActions.create.remoteId;
      node.remoteParent = rActions.create.remoteParent;

      return syncDb.update(node._id, node, callback);
    } else if(!rActions.delete) {

      //if remote path changed upload local version as new version on old path
      var remoteNode;
      return async.series([
        (cb) => {
          //create remote localy
          var name = rActions.rename ? rActions.rename.remoteName : node.name;
          var parent = rActions.move ? rActions.move.parent : node.parent;
          var remoteParent = rActions.move ? rActions.move.remoteParent : rActions.create.remoteParent;

          var newNode = {
            name: name,
            parent: parent,
            directory: node.directory,
            remoteId: node.remoteId,
            remoteParent: remoteParent,
            remoteActions: {create: rActions.create}
          }

          syncDb.create(newNode, (err, createdNode) => {
            remoteNode = createdNode;
            cb(err);
          });
        },
        (cb) => {
          delete node.remoteActions;
          delete node.remoteParent;
          delete node.remoteId;
          delete node.hash;
          delete node.version;

          syncDb.update(node._id, node, cb);
        },
        (cb) => {
          //as a new node has been created conflict resolution has to be executed for the new node
          resolveConflicts(null, remoteNode, cb);
        }
      ], callback);
    }
  }

  if(rActions.delete && lActions.delete) {
    //on both sides deleted, just remove it from db
    return syncDb.delete(node._id, (err) => {
      return callback(null);
    });
  }

  return callback(null);
}
function resolveFileConflicts(node, callback) {
  var rActions = node.remoteActions;
  var lActions = node.localActions;

  if(!rActions || !lActions) {
    //only one side changed, no conflicts
    return callback(null);
  }

  if(rActions.create && lActions.create) {
    //on both sides created or updated
    var currentLocalPath = utility.joinPath(node.parent, node.name);

    var localHash, stat;
    try {
      localHash = fsWrap.md5FileSync(currentLocalPath);
      stat = fsWrap.lstatSync(currentLocalPath);
    } catch(e) {
      logger.warning('resolveFileConflicts failed', {category: 'sync-delta', node, err: e});

      var err = new BlnDeltaError(e.message);
      throw err;
    }

    if(rActions.create.hash && rActions.create.hash === localHash && rActions.create.size === stat.size) {
      delete node.remoteActions;
      delete node.localActions;

      node.hash = localHash;
      node.version = rActions.create.version;
      node.size = stat.size;
      node.mtime = stat.mtime;
      node.ctime = stat.ctime;

      node.remoteId = rActions.create.remoteId;
      node.remoteParent = rActions.create.remoteParent;

      return syncDb.update(node._id, node, callback);
    } else if(!rActions.delete) {

      //if remote path changed upload local version as new version on old path
      var remoteNode;
      return async.series([
        (cb) => {
          //create remote localy
          var name = rActions.rename ? rActions.rename.remoteName : node.name;
          var parent = rActions.move ? rActions.move.parent : node.parent;
          var remoteParent = rActions.move ? rActions.move.remoteParent : rActions.create.remoteParent;

          var newNode = {
            name: name,
            parent: parent,
            directory: node.directory,
            remoteId: node.remoteId,
            remoteParent: remoteParent,
            remoteActions: {create: rActions.create}
          }

          syncDb.create(newNode, (err, createdNode) => {
            remoteNode = createdNode;
            cb(err);
          });
        },
        (cb) => {
          delete node.remoteActions;
          delete node.remoteParent;
          delete node.remoteId;
          delete node.hash;
          delete node.version;

          syncDb.update(node._id, node, cb);
        },
        (cb) => {
          //as a new node has been created conflict resolution has to be executed for the new node
          resolveConflicts(null, remoteNode, cb);
        }
      ], callback);
    }
  }

  if(rActions.delete && lActions.delete) {
    //on both sides deleted, just remove it from db
    return syncDb.delete(node._id, (err) => {
      return callback(null);
    });
  }

  return callback(null);
}
function resolveFileConflicts ( node , callback ) { var rActions = node . remoteActions ; var lActions = node . localActions ; if ( ! rActions || ! lActions ) { //only one side changed, no conflicts return callback ( null ) ; } if ( rActions . create && lActions . create ) { //on both sides created or updated var currentLocalPath = utility . joinPath ( node . parent , node . name ) ; var localHash , stat ; try { localHash = fsWrap . md5FileSync ( currentLocalPath ) ; stat = fsWrap . lstatSync ( currentLocalPath ) ; } catch ( e ) { logger . warning ( 'resolveFileConflicts failed' , { category : 'sync-delta' , node , err : e } ) ; var err = new BlnDeltaError ( e . message ) ; throw err ; } if ( rActions . create . hash && rActions . create . hash === localHash && rActions . create . size === stat . size ) { delete node . remoteActions ; delete node . localActions ; node . hash = localHash ; node . version = rActions . create . version ; node . size = stat . size ; node . mtime = stat . mtime ; node . ctime = stat . ctime ; node . remoteId = rActions . create . remoteId ; node . remoteParent = rActions . create . remoteParent ; return syncDb . update ( node . _id , node , callback ) ; } else if ( ! rActions . delete ) { //if remote path changed upload local version as new version on old path var remoteNode ; return async . series ( [ ( cb ) => { //create remote localy var name = rActions . rename ? rActions . rename . remoteName : node . name ; var parent = rActions . move ? rActions . move . parent : node . parent ; var remoteParent = rActions . move ? rActions . move . remoteParent : rActions . create . remoteParent ; var newNode = { name : name , parent : parent , directory : node . directory , remoteId : node . remoteId , remoteParent : remoteParent , remoteActions : { create : rActions . create } } syncDb . create ( newNode , ( err , createdNode ) => { remoteNode = createdNode ; cb ( err ) ; } ) ; } , ( cb ) => { delete node . remoteActions ; delete node . remoteParent ; delete node . remoteId ; delete node . hash ; delete node . version ; syncDb . update ( node . _id , node , cb ) ; } , ( cb ) => { //as a new node has been created conflict resolution has to be executed for the new node resolveConflicts ( null , remoteNode , cb ) ; } ] , callback ) ; } } if ( rActions . delete && lActions . delete ) { //on both sides deleted, just remove it from db return syncDb . delete ( node . _id , ( err ) => { return callback ( null ) ; } ) ; } return callback ( null ) ; }
Resolves conflicts for a file node

@param {Object} node - node with applied actions from database
@param {Function} callback - callback function
@returns {void} - no return value
Resolves conflicts for a file node