client/src/message-handler.js
function handlePatchAckResponse() {
    var syncedPath = data.content.path;

    function complete() {
      fsUtils.removeUnsynced(fs, syncedPath, function(err) {
        if(err && err.code !== 'ENOENT') {
          log.error('Failed to remove unsynced attribute for ' + syncedPath + ' in handlePatchAckResponse, complete()');
        }

        syncManager.syncNext(syncedPath);
      });
    }

    fs.lstat(syncedPath, function(err, stats) {
      if(err) {
        if(err.code !== 'ENOENT') {
          log.error('Failed to access ' + syncedPath + ' in handlePatchAckResponse');
          return fs.delaySync(function(delayErr, delayedPath) {
            if(delayErr) {
              log.error('Failed to delay upstream sync for ' + delayedPath + ' in handlePatchAckResponse');
            }
            onError(syncManager, err);
          });
        }

        // Non-existent paths usually due to renames or
        // deletes cannot be stamped with a checksum
        return complete();
      }

      if(!stats.isFile()) {
        return complete();
      }

      rsyncUtils.getChecksum(rawFs, syncedPath, function(err, checksum) {
        if(err) {
          log.error('Failed to get the checksum for ' + syncedPath + ' in handlePatchAckResponse');
          return fs.delaySync(function(delayErr, delayedPath) {
            if(delayErr) {
              log.error('Failed to delay upstream sync for ' + delayedPath + ' in handlePatchAckResponse while getting checksum');
            }
            onError(syncManager, err);
          });
        }

        fsUtils.setChecksum(rawFs, syncedPath, checksum, function(err) {
          if(err) {
            log.error('Failed to stamp the checksum for ' + syncedPath + ' in handlePatchAckResponse');
            return fs.delaySync(function(delayErr, delayedPath) {
              if(delayErr) {
                log.error('Failed to delay upstream sync for ' + delayedPath + ' in handlePatchAckResponse while setting checksum');
              }
              onError(syncManager, err);
            });
          }

          complete();
        });
      });
    });
  }
function handlePatchAckResponse() {
    var syncedPath = data.content.path;

    function complete() {
      fsUtils.removeUnsynced(fs, syncedPath, function(err) {
        if(err && err.code !== 'ENOENT') {
          log.error('Failed to remove unsynced attribute for ' + syncedPath + ' in handlePatchAckResponse, complete()');
        }

        syncManager.syncNext(syncedPath);
      });
    }

    fs.lstat(syncedPath, function(err, stats) {
      if(err) {
        if(err.code !== 'ENOENT') {
          log.error('Failed to access ' + syncedPath + ' in handlePatchAckResponse');
          return fs.delaySync(function(delayErr, delayedPath) {
            if(delayErr) {
              log.error('Failed to delay upstream sync for ' + delayedPath + ' in handlePatchAckResponse');
            }
            onError(syncManager, err);
          });
        }

        // Non-existent paths usually due to renames or
        // deletes cannot be stamped with a checksum
        return complete();
      }

      if(!stats.isFile()) {
        return complete();
      }

      rsyncUtils.getChecksum(rawFs, syncedPath, function(err, checksum) {
        if(err) {
          log.error('Failed to get the checksum for ' + syncedPath + ' in handlePatchAckResponse');
          return fs.delaySync(function(delayErr, delayedPath) {
            if(delayErr) {
              log.error('Failed to delay upstream sync for ' + delayedPath + ' in handlePatchAckResponse while getting checksum');
            }
            onError(syncManager, err);
          });
        }

        fsUtils.setChecksum(rawFs, syncedPath, checksum, function(err) {
          if(err) {
            log.error('Failed to stamp the checksum for ' + syncedPath + ' in handlePatchAckResponse');
            return fs.delaySync(function(delayErr, delayedPath) {
              if(delayErr) {
                log.error('Failed to delay upstream sync for ' + delayedPath + ' in handlePatchAckResponse while setting checksum');
              }
              onError(syncManager, err);
            });
          }

          complete();
        });
      });
    });
  }
function handlePatchAckResponse ( ) { var syncedPath = data . content . path ; function complete ( ) { fsUtils . removeUnsynced ( fs , syncedPath , function ( err ) { if ( err && err . code !== 'ENOENT' ) { log . error ( 'Failed to remove unsynced attribute for ' + syncedPath + ' in handlePatchAckResponse, complete()' ) ; } syncManager . syncNext ( syncedPath ) ; } ) ; } fs . lstat ( syncedPath , function ( err , stats ) { if ( err ) { if ( err . code !== 'ENOENT' ) { log . error ( 'Failed to access ' + syncedPath + ' in handlePatchAckResponse' ) ; return fs . delaySync ( function ( delayErr , delayedPath ) { if ( delayErr ) { log . error ( 'Failed to delay upstream sync for ' + delayedPath + ' in handlePatchAckResponse' ) ; } onError ( syncManager , err ) ; } ) ; } // Non-existent paths usually due to renames or // deletes cannot be stamped with a checksum return complete ( ) ; } if ( ! stats . isFile ( ) ) { return complete ( ) ; } rsyncUtils . getChecksum ( rawFs , syncedPath , function ( err , checksum ) { if ( err ) { log . error ( 'Failed to get the checksum for ' + syncedPath + ' in handlePatchAckResponse' ) ; return fs . delaySync ( function ( delayErr , delayedPath ) { if ( delayErr ) { log . error ( 'Failed to delay upstream sync for ' + delayedPath + ' in handlePatchAckResponse while getting checksum' ) ; } onError ( syncManager , err ) ; } ) ; } fsUtils . setChecksum ( rawFs , syncedPath , checksum , function ( err ) { if ( err ) { log . error ( 'Failed to stamp the checksum for ' + syncedPath + ' in handlePatchAckResponse' ) ; return fs . delaySync ( function ( delayErr , delayedPath ) { if ( delayErr ) { log . error ( 'Failed to delay upstream sync for ' + delayedPath + ' in handlePatchAckResponse while setting checksum' ) ; } onError ( syncManager , err ) ; } ) ; } complete ( ) ; } ) ; } ) ; } ) ; }
As soon as an upstream sync happens, the file synced becomes the last synced version and must be stamped with its checksum to version it and the unsynced attribute must be removed
As soon as an upstream sync happens the file synced becomes the last synced version and must be stamped with its checksum to version it and the unsynced attribute must be removed