repository maintainence code
[nodejs-repoproxy.git] / lib / maintain.js
index e336d4a..cbed4a2 100644 (file)
@@ -14,11 +14,14 @@ function maintainCache() {
                switch(global.repoproxy.repo[index]["type"]) {
                case "apt":
                        console.log("Scanning '%s' as apt", index);
-                       repoapt.maintain(global.repoproxy.repo[index]);
+                       var walkin = path.normalize(global.repoproxy.cacheDir + "/" + index);
+                       walkDir(walkin, function(err, list) {
+                               repoapt.maintain(index, global.repoproxy.repo[index], list);
+                       })
                        break;
                case "yum":
-                       console.log("Scanning '%s' as apt", index);
-                       repoyum.maintain(global.repoproxy.repo[index]);
+                       //console.log("Scanning '%s' as apt", index);
+                       //repoyum.maintain(global.repoproxy.repo[index]);
                        break;
                }
        }
@@ -33,6 +36,34 @@ exports.startTimer = function() {
        setInterval(maintainCache, cacheTimer);
 }
 
+// this code comes frmo http://stackoverflow.com/questions/5827612/node-js-fs-readdir-recursive-directory-search
+function walkDir(dir, done) {
+       var results = [];
+       
+       fs.readdir(dir, function(err, list) {
+               if (err) return done(err);
+               var i = 0;
+               (function next() {
+                       var file = list[i++];
+                       if (!file) return done(null, results);
+                       file = path.normalize(dir + "/" + file);
+                       fs.stat(file, function(err, stat) {
+                               if (stat && stat.isDirectory()) {
+                                       walkDir(file, function(err, res) {
+                                               results = results.concat(res);
+                                               next();
+                                       });
+                               } else {
+                                       if(!file.match(/.*\.meta.*\.filesize/)) results.push(file);
+                                       next();
+                               }
+                       });
+               })();
+       });
+};
+
+exports.walkDir = walkDir;
+
 function cleanupRoutine() {
        
 }
\ No newline at end of file