lib/delta/delta.js
function renameRemoteNode(node, name, callback) {
  var rActions = node.remoteActions || {};

  var newLocalName = utility.renameConflictNodeRemote(name);
  var oldLocalName = node.name;

  var newLocalPath = utility.joinPath(node.parent, newLocalName);
  var oldLocalPath = utility.joinPath(node.parent, oldLocalName);

  if(!rActions.create && fsWrap.existsSync(oldLocalPath)) {
    try {
      fsWrap.renameSync(oldLocalPath, newLocalPath);
    } catch(err) {
      logger.warning('rename local node failed', {category: 'sync-delta', oldLocalPath, newLocalPath, err})
      throw new BlnDeltaError(err.message);

      return;
    }
  }

  node.name = newLocalName;
  node.localActions = node.localActions || {};

  var remoteId = node.remoteId || node.remoteActions.create.remoteId;

  return blnApi.renameNode({remoteId, name: node.name}, (err) => {
    if(err) {
      logger.warning('rename remote node failed', {category: 'sync-delta', params: {remoteId, name: node.name}, err});
      throw new BlnDeltaError(err.message);

      return;
    }

    if(rActions.rename) {
      delete node.remoteActions.rename;
    }

    syncDb.update(node._id, node, callback);
  });
}
function renameRemoteNode(node, name, callback) {
  var rActions = node.remoteActions || {};

  var newLocalName = utility.renameConflictNodeRemote(name);
  var oldLocalName = node.name;

  var newLocalPath = utility.joinPath(node.parent, newLocalName);
  var oldLocalPath = utility.joinPath(node.parent, oldLocalName);

  if(!rActions.create && fsWrap.existsSync(oldLocalPath)) {
    try {
      fsWrap.renameSync(oldLocalPath, newLocalPath);
    } catch(err) {
      logger.warning('rename local node failed', {category: 'sync-delta', oldLocalPath, newLocalPath, err})
      throw new BlnDeltaError(err.message);

      return;
    }
  }

  node.name = newLocalName;
  node.localActions = node.localActions || {};

  var remoteId = node.remoteId || node.remoteActions.create.remoteId;

  return blnApi.renameNode({remoteId, name: node.name}, (err) => {
    if(err) {
      logger.warning('rename remote node failed', {category: 'sync-delta', params: {remoteId, name: node.name}, err});
      throw new BlnDeltaError(err.message);

      return;
    }

    if(rActions.rename) {
      delete node.remoteActions.rename;
    }

    syncDb.update(node._id, node, callback);
  });
}
function renameRemoteNode ( node , name , callback ) { var rActions = node . remoteActions || { } ; var newLocalName = utility . renameConflictNodeRemote ( name ) ; var oldLocalName = node . name ; var newLocalPath = utility . joinPath ( node . parent , newLocalName ) ; var oldLocalPath = utility . joinPath ( node . parent , oldLocalName ) ; if ( ! rActions . create && fsWrap . existsSync ( oldLocalPath ) ) { try { fsWrap . renameSync ( oldLocalPath , newLocalPath ) ; } catch ( err ) { logger . warning ( 'rename local node failed' , { category : 'sync-delta' , oldLocalPath , newLocalPath , err } ) throw new BlnDeltaError ( err . message ) ; return ; } } node . name = newLocalName ; node . localActions = node . localActions || { } ; var remoteId = node . remoteId || node . remoteActions . create . remoteId ; return blnApi . renameNode ( { remoteId , name : node . name } , ( err ) => { if ( err ) { logger . warning ( 'rename remote node failed' , { category : 'sync-delta' , params : { remoteId , name : node . name } , err } ) ; throw new BlnDeltaError ( err . message ) ; return ; } if ( rActions . rename ) { delete node . remoteActions . rename ; } syncDb . update ( node . _id , node , callback ) ; } ) ; }
renames a conflicting node remotely

@param {Object} node - node A from database
@param {string} name - current name of the file
@param {Function} callback - callback function
@returns {void} - no return value
renames a conflicting node remotely