Code coverage report for lib/monitor/changed-since.js

Statements: 9.68% (3 / 31)      Branches: 0% (0 / 23)      Functions: 0% (0 / 7)      Lines: 9.68% (3 / 31)     

All files » lib/monitor/ » changed-since.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 571         1     1                                                                                                
var fs = require('fs'),
    utils = require('../utils'),
    config = require('../config'),
    path = require('path');
 
module.exports = changedSince;
 
// This is a fallback function is only used if fs.watch does not work
function changedSince(time, dir, callback) {
  if (!callback) {
    callback = dir;
  }
 
  var changed = [],
      todo = 0,
      done = function () { // why you no use async, remy? – Remy
        todo--;
        if (todo === 0) {
          callback(changed);
        }
      };
 
  dir = dir && typeof dir !== 'function' ? [dir] : config.dirs;
 
  dir.forEach(function (dir) {
    todo++;
    fs.readdir(dir, function (err, files) {
      if (err) {
        return;
      }
 
      files.forEach(function (file) {
        if (config.options.hidden === true || !config.options.hidden && file.indexOf('.') !== 0) {
          todo++;
          file = path.resolve(dir + path.sep + file);
          fs.stat(file, function (err, stat) {
            if (stat) {
              if (stat.isDirectory()) {
                todo++;
                changedSince(time, file, function (subChanged) {
                  if (subChanged.length) {
                    changed = changed.concat(subChanged);
                  }
                  done();
                });
              } else if (stat.mtime > time) {
                changed.push(file);
              }
            }
            done();
          });
        }
      });
      done();
    });
  });
}