1 var fs = require("fs");
2 var http = require("http");
3 var url = require("url");
4 var path = require("path");
5 var repoapt = require("./repo-apt.js");
6 var repoyum = require("./repo-yum.js");
8 function maintainCache() {
9 // TODO i should check that im already running here and exit if i am
10 console.log("Cache maintainence routine starting...");
11 for(var index in global.repoproxy.repo) {
12 console.log("start cleanup in ", index);
13 console.log("cleanup array ", global.repoproxy.repo[index]);
14 switch(global.repoproxy.repo[index]["type"]) {
16 console.log("Scanning '%s' as apt", index);
17 var walkin = path.normalize(global.repoproxy.cacheDir + "/" + index);
18 walkDir(walkin, function(err, list) {
19 repoapt.maintain(index, global.repoproxy.repo[index], list);
23 //console.log("Scanning '%s' as apt", index);
24 //repoyum.maintain(global.repoproxy.repo[index]);
28 console.log("Cache maintainence routine ended...");
31 exports.startTimer = function() {
32 // our once-a-day cache maintainer
33 var cacheTimer = global.repoproxy.scancache*3600*1000;
34 //var cacheTimer = global.repoproxy.scancache*100;
36 setInterval(maintainCache, cacheTimer);
39 // this code comes frmo http://stackoverflow.com/questions/5827612/node-js-fs-readdir-recursive-directory-search
40 function walkDir(dir, done) {
43 fs.readdir(dir, function(err, list) {
44 if (err) return done(err);
48 if (!file) return done(null, results);
49 file = path.normalize(dir + "/" + file);
50 fs.stat(file, function(err, stat) {
51 if (stat && stat.isDirectory()) {
52 walkDir(file, function(err, res) {
53 results = results.concat(res);
57 if(!file.match(/.*\.meta.*\.filesize/)) results.push(file);
65 exports.walkDir = walkDir;
67 function cleanupRoutine() {