X-Git-Url: http://git.pjr.cc/?p=nodejs-repoproxy.git;a=blobdiff_plain;f=lib%2Fmaintain.js;fp=lib%2Fmaintain.js;h=cd8ea8b5bf9db930fd90bb6b9cd538e64e39af75;hp=fe19a00e9de7a591adab0c92efd04b51be4c1f46;hb=9ce3e2a4e56f91fdc7d6295d3d064f2739955404;hpb=3933776341028e83d89e0f888fff3e6319230abf diff --git a/lib/maintain.js b/lib/maintain.js index fe19a00..cd8ea8b 100644 --- a/lib/maintain.js +++ b/lib/maintain.js @@ -8,7 +8,14 @@ var log = require("./log.js"); function maintainCache() { // TODO i should check that im already running here and exit if i am - log.debug("Cache maintainence routine starting..."); + if(global.repoproxy.maintain==1) { + log.warning("cache maintenance routine started, but its already running"); + return; + } + + global.repoproxy.maintain = 1; + + log.info("Cache maintainence routine starting..."); for(var index in global.repoproxy.repo) { //log.debug("start cleanup in ", index); //log.debug("cleanup array ", global.repoproxy.repo[index]); @@ -32,7 +39,36 @@ function maintainCache() { break; } } - log.debug("Cache maintainence routine ended..."); + log.info("Cache maintainence routine ended..."); + + + + log.info("beginning cache trash cleanup"); + // TODO: do this bit properly, check that globals are set properly + var spawn = require('child_process').spawn; + + // TODO: be carefull we actually have a place to remove + if(typeof global.repoproxy == "undefined") { + log.error("serious issue, globals not accessible?"); + process.exit(10); + } else if(typeof global.repoproxy.cacheDir == "undefined") { + log.error("serious issue, globals not accessible (cache check)?"); + process.exit(10); + } else { + var remove = spawn("rm", ["-r", global.repoproxy.cacheDir + "/.cleanup/*"]); + remove.on("close", function(code, sig) { + log.debug("remove ended with %d, %d", code, sig); + }); + remove.stderr.on("data", function(line) { + log.debug("stderr from lazy remove: ", line.toString("utf8")); + }); + remove.stdout.on("data", function(line) { + log.debug("stdout from lazy remove: ", line.toString("ascii")); + }); + } + log.info("Trash empty"); + + global.repoproxy.maintain = 0; } exports.startTimer = function() {