lib/rsync/rsync-utils.js
function generateChecksums(fs, paths, stampNode, callback) {
  // Maybe stampNode was not passed in
  if(typeof callback !== 'function') {
    callback = findCallback(callback, stampNode);
    stampNode = false;
  }

  var paramError = validateParams(fs, paths);
  if(paramError) {
    return callback(paramError);
  }

  var checksumList = [];

  function ChecksumNode(path, type, checksum) {
    this.path = path;
    this.type = type;
    this.checksum = checksum;
  }

  function addChecksumNode(path, nodeType, checksum, callback) {
    var checksumNode;

    // If no checksum was passed in
    if(typeof checksum === 'function') {
      callback = checksum;
      checksumNode = new ChecksumNode(path, nodeType);
    } else {
      checksumNode = new ChecksumNode(path, nodeType, checksum);
    }

    checksumList.push(checksumNode);
    callback();
  }

  // Only calculate the checksums for synced paths
  function maybeAddChecksumNode(path, nodeType, callback) {
    fsUtils.isPathUnsynced(fs, path, function(err, unsynced) {
      if(err) {
        return callback(err);
      }

      if(unsynced) {
        return callback();
      }

      getChecksum(fs, path, function(err, checksum) {
        if(err) {
          return callback(err);
        }
        // If we shouldn't add the checksum stamp or
        // the node does not exist (cannot add a stamp)
        // immediately add the checksum
        if(!stampNode || checksum === "") {
          return addChecksumNode(path, nodeType, checksum, callback);
        }

        // Stamp the node with the checksum
        fsUtils.setChecksum(fs, path, checksum, function(err) {
          if(err) {
            return callback(err);
          }

          addChecksumNode(path, nodeType, checksum, callback);
        });
      });
    });
  }

  function calcChecksum(path, callback) {
    fs.lstat(path, function(err, stat) {
      var nodeType = stat && stat.type;

      if(err) {
        if(err.code !== 'ENOENT') {
          return callback(err);
        }

        // Checksums for non-existent files
        maybeAddChecksumNode(path, nodeType, callback);
      } else if(stat.isDirectory()) {
        // Directory checksums are not calculated i.e. are undefined
        addChecksumNode(path, nodeType, callback);
      } else {
        // Checksums for synced files/links
        maybeAddChecksumNode(path, nodeType, callback);
      }
    });
  }

  async.eachSeries(paths, calcChecksum, function(err) {
    if(err) {
      return callback(err);
    }

    callback(null, checksumList);
  });
}
function generateChecksums(fs, paths, stampNode, callback) {
  // Maybe stampNode was not passed in
  if(typeof callback !== 'function') {
    callback = findCallback(callback, stampNode);
    stampNode = false;
  }

  var paramError = validateParams(fs, paths);
  if(paramError) {
    return callback(paramError);
  }

  var checksumList = [];

  function ChecksumNode(path, type, checksum) {
    this.path = path;
    this.type = type;
    this.checksum = checksum;
  }

  function addChecksumNode(path, nodeType, checksum, callback) {
    var checksumNode;

    // If no checksum was passed in
    if(typeof checksum === 'function') {
      callback = checksum;
      checksumNode = new ChecksumNode(path, nodeType);
    } else {
      checksumNode = new ChecksumNode(path, nodeType, checksum);
    }

    checksumList.push(checksumNode);
    callback();
  }

  // Only calculate the checksums for synced paths
  function maybeAddChecksumNode(path, nodeType, callback) {
    fsUtils.isPathUnsynced(fs, path, function(err, unsynced) {
      if(err) {
        return callback(err);
      }

      if(unsynced) {
        return callback();
      }

      getChecksum(fs, path, function(err, checksum) {
        if(err) {
          return callback(err);
        }
        // If we shouldn't add the checksum stamp or
        // the node does not exist (cannot add a stamp)
        // immediately add the checksum
        if(!stampNode || checksum === "") {
          return addChecksumNode(path, nodeType, checksum, callback);
        }

        // Stamp the node with the checksum
        fsUtils.setChecksum(fs, path, checksum, function(err) {
          if(err) {
            return callback(err);
          }

          addChecksumNode(path, nodeType, checksum, callback);
        });
      });
    });
  }

  function calcChecksum(path, callback) {
    fs.lstat(path, function(err, stat) {
      var nodeType = stat && stat.type;

      if(err) {
        if(err.code !== 'ENOENT') {
          return callback(err);
        }

        // Checksums for non-existent files
        maybeAddChecksumNode(path, nodeType, callback);
      } else if(stat.isDirectory()) {
        // Directory checksums are not calculated i.e. are undefined
        addChecksumNode(path, nodeType, callback);
      } else {
        // Checksums for synced files/links
        maybeAddChecksumNode(path, nodeType, callback);
      }
    });
  }

  async.eachSeries(paths, calcChecksum, function(err) {
    if(err) {
      return callback(err);
    }

    callback(null, checksumList);
  });
}
function generateChecksums ( fs , paths , stampNode , callback ) { // Maybe stampNode was not passed in if ( typeof callback !== 'function' ) { callback = findCallback ( callback , stampNode ) ; stampNode = false ; } var paramError = validateParams ( fs , paths ) ; if ( paramError ) { return callback ( paramError ) ; } var checksumList = [ ] ; function ChecksumNode ( path , type , checksum ) { this . path = path ; this . type = type ; this . checksum = checksum ; } function addChecksumNode ( path , nodeType , checksum , callback ) { var checksumNode ; // If no checksum was passed in if ( typeof checksum === 'function' ) { callback = checksum ; checksumNode = new ChecksumNode ( path , nodeType ) ; } else { checksumNode = new ChecksumNode ( path , nodeType , checksum ) ; } checksumList . push ( checksumNode ) ; callback ( ) ; } // Only calculate the checksums for synced paths function maybeAddChecksumNode ( path , nodeType , callback ) { fsUtils . isPathUnsynced ( fs , path , function ( err , unsynced ) { if ( err ) { return callback ( err ) ; } if ( unsynced ) { return callback ( ) ; } getChecksum ( fs , path , function ( err , checksum ) { if ( err ) { return callback ( err ) ; } // If we shouldn't add the checksum stamp or // the node does not exist (cannot add a stamp) // immediately add the checksum if ( ! stampNode || checksum === "" ) { return addChecksumNode ( path , nodeType , checksum , callback ) ; } // Stamp the node with the checksum fsUtils . setChecksum ( fs , path , checksum , function ( err ) { if ( err ) { return callback ( err ) ; } addChecksumNode ( path , nodeType , checksum , callback ) ; } ) ; } ) ; } ) ; } function calcChecksum ( path , callback ) { fs . lstat ( path , function ( err , stat ) { var nodeType = stat && stat . type ; if ( err ) { if ( err . code !== 'ENOENT' ) { return callback ( err ) ; } // Checksums for non-existent files maybeAddChecksumNode ( path , nodeType , callback ) ; } else if ( stat . isDirectory ( ) ) { // Directory checksums are not calculated i.e. are undefined addChecksumNode ( path , nodeType , callback ) ; } else { // Checksums for synced files/links maybeAddChecksumNode ( path , nodeType , callback ) ; } } ) ; } async . eachSeries ( paths , calcChecksum , function ( err ) { if ( err ) { return callback ( err ) ; } callback ( null , checksumList ) ; } ) ; }
Generate checksums for an array of paths to be used for comparison It also takes an optional parameter called stampNode, a boolean which indicates whether the checksum should be stamped as an xattr on the node.
Generate checksums for an array of paths to be used for comparison It also takes an optional parameter called stampNode a boolean which indicates whether the checksum should be stamped as an xattr on the node .