fixing repo bits
[nodejs-repoproxy.git] / unittests / recurse.js
1 var fs = require("fs");
2 var path = require("path");
3                 
4
5 // comes from http://stackoverflow.com/questions/5827612/node-js-fs-readdir-recursive-directory-search
6 var walk = function(dir, done) {
7         var results = [];
8         
9         fs.readdir(dir, function(err, list) {
10                 if (err) return done(err);
11                 var i = 0;
12                 (function next() {
13                         var file = list[i++];
14                         if (!file) return done(null, results);
15                         file = path.normalize(dir + "/" + file);
16                         fs.stat(file, function(err, stat) {
17                                 if (stat && stat.isDirectory()) {
18                                         walk(file, function(err, res) {
19                                                 results = results.concat(res);
20                                                 next();
21                                         });
22                                 } else {
23                                         if(!file.match(/.*\.meta.*\.filesize/)) results.push(file);
24                                         next();
25                                 }
26                         });
27                 })();
28         });
29 };
30
31 walk("/tmp/cache/ubuntu", function(err, res) {
32         console.log("result: ", res);
33 });