Skip to content
This repository
  • 2 commits
  • 1 file changed
  • 0 comments
  • 2 contributors
Apr 26, 2012
Arnout Kazemier Edgecase fix:
It's currently possible that the last watched file is ignored by a filter function
or by the `ignoreDotFiles` option causing the callback to be never called.
408c891
Mikeal Rogers Merge pull request #29 from 3rd-Eden/master
watch fails to watch when the last file in it's queue is ignored
cbb9da4

Showing 1 changed file with 12 additions and 9 deletions. Show diff stats Hide diff stats

  1. 21  main.js
21  main.js
... ...
@@ -1,11 +1,11 @@
1 1
 // Copyright 2010-2011 Mikeal Rogers
2  
-// 
  2
+//
3 3
 //    Licensed under the Apache License, Version 2.0 (the "License");
4 4
 //    you may not use this file except in compliance with the License.
5 5
 //    You may obtain a copy of the License at
6  
-// 
  6
+//
7 7
 //        http://www.apache.org/licenses/LICENSE-2.0
8  
-// 
  8
+//
9 9
 //    Unless required by applicable law or agreed to in writing, software
10 10
 //    distributed under the License is distributed on an "AS IS" BASIS,
11 11
 //    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,7 +18,7 @@ var sys = require('util')
18 18
   , events = require('events')
19 19
   ;
20 20
 
21  
-function walk (dir, options, callback) { 
  21
+function walk (dir, options, callback) {
22 22
   if (!callback) {callback = options; options = {}}
23 23
   if (!callback.files) callback.files = {};
24 24
   if (!callback.pending) callback.pending = 0;
@@ -33,7 +33,9 @@ function walk (dir, options, callback) {
33 33
         f = path.join(dir, f);
34 34
         callback.pending += 1;
35 35
         fs.stat(f, function (err, stat) {
36  
-          var enoent = false;
  36
+          var enoent = false
  37
+            , done = false;
  38
+
37 39
           if (err) {
38 40
             if (err.code !== 'ENOENT') {
39 41
               return callback(err);
@@ -42,12 +44,13 @@ function walk (dir, options, callback) {
42 44
             }
43 45
           }
44 46
           callback.pending -= 1;
  47
+          done = callback.pending === 0;
45 48
           if (!enoent) {
46  
-            if (options.ignoreDotFiles && path.basename(f)[0] === '.') return;
47  
-            if (options.filter && options.filter(f, stat)) return;
  49
+            if (options.ignoreDotFiles && path.basename(f)[0] === '.') return done && callback(null, callback.files);
  50
+            if (options.filter && options.filter(f, stat)) return done && callback(null, callback.files);
48 51
             callback.files[f] = stat;
49 52
             if (stat.isDirectory()) walk(f, options, callback);
50  
-            if (callback.pending === 0) callback(null, callback.files);
  53
+            if (done) callback(null, callback.files);
51 54
           }
52 55
         })
53 56
       })
@@ -55,7 +58,7 @@ function walk (dir, options, callback) {
55 58
     })
56 59
     if (callback.pending === 0) callback(null, callback.files);
57 60
   })
58  
-  
  61
+
59 62
 }
60 63
 exports.watchTree = function ( root, options, callback ) {
61 64
   if (!callback) {callback = options; options = {}}

No commit comments for this range

Something went wrong with that request. Please try again.