[Pkg-javascript-commits] [node-findit] 01/06: add bugfixing patch

Andrew Kelley andrewrk-guest at moszumanska.debian.org
Thu Oct 16 20:12:30 UTC 2014


This is an automated email from the git hooks/post-receive script.

andrewrk-guest pushed a commit to branch master
in repository node-findit.

commit 4a605a375b8637897b1714f1270da04c491fae9d
Author: Andrew Kelley <superjoe30 at gmail.com>
Date:   Thu Oct 16 20:02:16 2014 +0000

    add bugfixing patch
---
 debian/patches/0001-leaner-cleaner-findit.patch | 365 ++++++++++++++++++++++++
 debian/patches/series                           |   1 +
 2 files changed, 366 insertions(+)

diff --git a/debian/patches/0001-leaner-cleaner-findit.patch b/debian/patches/0001-leaner-cleaner-findit.patch
new file mode 100644
index 0000000..10939b0
--- /dev/null
+++ b/debian/patches/0001-leaner-cleaner-findit.patch
@@ -0,0 +1,365 @@
+Description: fix all the bugs and add symlink API
+From: Andrew Kelley <superjoe30 at gmail.com>
+Forwarded: https://github.com/substack/node-findit/pull/34
+--- a/index.js
++++ b/index.js
+@@ -1,187 +1,121 @@
+ var EventEmitter = require('events').EventEmitter;
+-var rfs = require('fs');
++var fs = require('fs');
+ var path = require('path');
+ 
+-module.exports = function walk (dir, opts, emitter, dstat) {
+-    if (!opts) opts = {};
+-    var fdir = opts._original || dir;
+-    opts._original = undefined;
+-    var fs = opts.fs || rfs;
+-    
+-    if (!emitter) {
+-        emitter = new EventEmitter;
+-        emitter.stop = function () {
+-            emitter._stopped = true;
+-            emitter.emit('stop');
+-        };
+-        emitter._pending = 0;
+-        emitter._seen = {};
+-    }
+-    
+-    if (dstat) {
+-        var stopped = false;
+-        emitter.emit('directory', fdir, dstat, function stop () {
+-            stopped = true;
+-        });
+-        emitter.emit('path', fdir, dstat);
+-        if (!stopped) {
+-            emitter._pending ++;
+-            fs.readdir(dir, function (err, files) {
+-                emitter._pending --;
+-                onreaddir(dir, err, files);
+-            });
+-        }
+-        else check()
+-    }
+-    else {
+-        emitter._pending ++;
+-        fs.lstat(dir, function (err, stat) {
+-            emitter._pending --;
+-            onlstat(err, stat);
+-        });
+-    }
+-    function onlstat (err, stat) {
+-        if (emitter._stopped) return;
+-        
+-        if (err) {
+-            if (!err.path) err.path = dir;
+-            emitter.emit('error', err);
+-            return check();
+-        }
+-        emitter._seen[stat.ino || dir] = true;
+-        
+-        if (stat.isSymbolicLink() && opts.followSymlinks) {
+-            emitter.emit('link', fdir, stat);
+-            emitter._pending ++;
+-            fs.readlink(dir, function (err, rfile) {
+-                if (emitter._stopped) return;
+-                emitter._pending --;
+-                if (err) {
+-                    if (!err.path) err.path = dir;
+-                    emitter.emit('error', err);
+-                    return check();
+-                }
+-                var file_ = path.resolve(dir, rfile);
+-                emitter.emit('readlink', fdir, file_);
+-                emitter._pending ++;
+-                fs.lstat(file_, function (err, stat) {
+-                    emitter._pending --;
+-                    onstat(err, stat);
+-                });
+-            });
+-        }
+-        else if (stat.isSymbolicLink()) {
+-            emitter.emit('link', fdir, stat);
+-            emitter.emit('path', fdir, stat);
+-            check();
+-        }
+-        else if (stat.isDirectory()) {
+-            var stopped = false;
+-            emitter.emit('directory', fdir, stat, function stop () {
+-                stopped = true;
+-            });
+-            emitter.emit('path', fdir, stat);
+-            if (!stopped) {
+-                emitter._pending ++;
+-                fs.readdir(dir, function (err, files) {
+-                    emitter._pending --;
+-                    onreaddir(dir, err, files);
+-                });
+-            }
+-            else check()
+-        }
+-        else {
+-            emitter.emit('file', fdir, stat);
+-            emitter.emit('path', fdir, stat);
+-            check();
+-        }
+-    }
+-    
+-    return emitter;
+-    
+-    function check () {
+-        if (emitter._pending === 0) finish();
+-    }
+-    
+-    function finish () {
+-        emitter.emit('end');
+-        emitter._stopped = true;
+-    }
+-    
+-    function onreaddir (dir, err, files) {
+-        if (emitter._stopped) return;
+-        
+-        if (err) {
+-            if (!err.path) err.path = dir;
+-            emitter.emit('error', err);
+-            return check();
+-        }
+-        
+-        files.forEach(function (rfile) {
+-            var file = path.join(fdir, rfile);
+-            
+-            emitter._pending ++;
+-            fs.lstat(file, function (err, stat) {
+-                emitter._pending --;
+-                
+-                if (emitter._stopped) return;
+-                if (err) {
+-                    if (!err.path) err.path = file;
+-                    emitter.emit('error', err);
+-                    check()
+-                }
+-                else onstat(file, stat)
+-            });
+-        });
+-       check();
+-    }
+-    
+-    function onstat (file, stat, original) {
+-        if (emitter._seen[stat.ino || file]) return check();
+-        emitter._seen[stat.ino || file] = true;
+-        
+-        if (stat.isDirectory()) {
+-            if (original) opts._original = original;
+-            walk(file, opts, emitter, stat);
+-            check();
+-        }
+-        else if (stat.isSymbolicLink() && opts.followSymlinks) {
+-            emitter.emit('link', file, stat);
+-            
+-            fs.readlink(file, function (err, rfile) {
+-                if (emitter._stopped) return;
+-                if (err) {
+-                    if (!err.path) err.path = file;
+-                    emitter.emit('error', err);
+-                    return check();
+-                }
+-                var file_ = path.resolve(path.dirname(file), rfile);
+-                
+-                emitter.emit('readlink', file, file_);
+-                emitter._pending ++;
+-                fs.lstat(file_, function (err, stat_) {
+-                    emitter._pending --;
+-                    if (emitter._stopped) return;
+-                    if (err) {
+-                        if (!err.path) err.path = file_;
+-                        emitter.emit('error', err);
+-                        return check();
+-                    }
+-                    
+-                    onstat(file_, stat_, file);
+-                    check();
+-                });
+-            });
+-        }
+-        else if (stat.isSymbolicLink()) {
+-            emitter.emit('link', file, stat);
+-            emitter.emit('path', file, stat);
+-            check();
++module.exports = findit;
++
++function findit(basedir, opts) {
++  opts = opts || {};
++  var followSymlinks = !!opts.followSymlinks;
++  var myFs = opts.fs || fs;
++  var emitter = new EventEmitter();
++  var stopped = false;
++  var pending = 0;
++  var seen = {};
++
++  emitter.stop = stop;
++  walkPath(basedir);
++  return emitter;
++
++  function recursiveReadDir(basedir, linkPath) {
++    pendStart();
++    myFs.readdir(basedir, function(err, entries) {
++      if (stopped) return;
++      if (err) {
++        handleError(err, basedir);
++        pendEnd();
++        return;
++      }
++      entries.forEach(function(entry) {
++        var fullPath = path.join(basedir, entry);
++        var fullLinkPath = linkPath && path.join(linkPath, entry);
++        walkPath(fullPath, fullLinkPath);
++      });
++      pendEnd();
++    });
++  }
++
++  function walkPath(fullPath, linkPath) {
++    pendStart();
++    myFs.lstat(fullPath, function(err, stats) {
++      if (stopped) return;
++      if (err) {
++        handleError(err, fullPath);
++        pendEnd();
++        return;
++      }
++      emitter.emit('path', fullPath, stats, linkPath);
++      var dirStopped = false;
++      if (stats.isDirectory()) {
++        if (seen[fullPath]) {
++          err = new Error("file system loop detected");
++          err.code = 'ELOOP';
++          handleError(err, fullPath);
++          pendEnd();
++          return;
+         }
+-        else {
+-            emitter.emit('file', file, stat);
+-            emitter.emit('path', file, stat);
+-            check();
++        seen[fullPath] = true;
++
++        emitter.emit('directory', fullPath, stats, stopDir, linkPath);
++        if (!dirStopped) recursiveReadDir(fullPath, linkPath);
++      } else if (stats.isFile()) {
++        if (!seen[fullPath]) {
++          seen[fullPath] = true;
++          emitter.emit('file', fullPath, stats, linkPath);
+         }
++      } else if (stats.isSymbolicLink()) {
++        emitter.emit('link', fullPath, stats, linkPath);
++        if (followSymlinks) recursiveReadLink(fullPath);
++      }
++      pendEnd();
++
++      function stopDir() {
++        dirStopped = true;
++      }
++    });
++  }
++
++  function recursiveReadLink(linkPath) {
++    pendStart();
++    myFs.readlink(linkPath, function(err, linkString) {
++      if (stopped) return;
++      if (err) {
++        handleError(err, linkPath);
++        pendEnd();
++        return;
++      }
++      var fullPath = path.join(path.dirname(linkPath), linkString);
++      emitter.emit('readlink', linkPath, fullPath);
++      walkPath(fullPath, linkPath);
++      pendEnd();
++    });
++  }
++
++  function stop() {
++    if (stopped) return;
++    stopped = true;
++    emitter.emit('stop');
++  }
++
++  function handleError(err, errPath) {
++    if (!err || stopped) return;
++    err.path = errPath;
++    emitter.emit('error', err);
++  }
++
++  function pendStart() {
++    pending += 1;
++  }
++
++  function pendEnd() {
++    if (stopped) return;
++    pending -= 1;
++    if (pending === 0) {
++      emitter.emit('end');
++    } else if (pending < 0) {
++      // this should never happen; if this gets thrown we need to debug findit
++      // and this stack trace will help.
++      throw new Error("pendEnd called too many times");
+     }
+-};
++  }
++}
+--- a/readme.markdown
++++ b/readme.markdown
+@@ -58,15 +58,19 @@ fire.
+ 
+ # events
+ 
+-## finder.on('path', function (file, stat) {})
++## finder.on('path', function (file, stat, linkPath) {})
+ 
+ For each file, directory, and symlink `file`, this event fires.
+ 
+-## finder.on('file', function (file, stat) {})
++If `followSymlinks` is `true`, then `linkPath` will be defined when `file`
++was found via a symlink. In this situation, `linkPath` is the path including
++the symlink; `file` is the resolved actual location on disk.
++
++## finder.on('file', function (file, stat, linkPath) {})
+ 
+ For each file, this event fires.
+ 
+-## finder.on('directory', function (dir, stat, stop) {})
++## finder.on('directory', function (dir, stat, stop, linkPath) {})
+ 
+ For each directory, this event fires with the path `dir`.
+ 
+--- a/test/symlinks.js
++++ b/test/symlinks.js
+@@ -55,15 +55,16 @@ test('links', function (t) {
+         t.end();
+     }
+ });
+-
+ test('follow links', function (t) {
+     helper(t, __dirname + '/symlinks/dir1', { followSymlinks: true }, done);
+     
+     function done (data) {
+-        t.equal(data.errors.length, 1);
++        t.equal(data.errors.length, 2);
++        t.equal(
++            data.errors[0].path, __dirname + '/symlinks/dir1/does-not-exist'
++        );
+         t.equal(
+-            data.errors[0].path, __dirname
+-            + '/symlinks/dir1/does-not-exist'
++            data.errors[1].path, __dirname + '/symlinks/dir1'
+         );
+         
+         t.deepEqual(data.symlinks, [
+@@ -71,7 +72,7 @@ test('follow links', function (t) {
+             'link-to-file'
+         ]);
+         t.deepEqual(data.files, ['file', 'file1', 'file2']);
+-        t.deepEqual(data.dirs, [ 'dir1', 'link-to-dir2' ]);
++        t.deepEqual(data.dirs, [ 'dir1', 'dir2' ]);
+         t.end();
+     }
+ });
diff --git a/debian/patches/series b/debian/patches/series
new file mode 100644
index 0000000..ea4aebe
--- /dev/null
+++ b/debian/patches/series
@@ -0,0 +1 @@
+0001-leaner-cleaner-findit.patch

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-findit.git



More information about the Pkg-javascript-commits mailing list