From: Paul J R Date: Fri, 21 Jun 2013 01:17:56 +0000 (+1000) Subject: fixing meta data aging X-Git-Url: http://git.pjr.cc/?a=commitdiff_plain;h=efd3942c83ad1235b32f983f53f89c984ef81db4;p=nodejs-repoproxy.git fixing meta data aging --- diff --git a/lib/maintain.js b/lib/maintain.js index cbed4a2..b740a78 100644 --- a/lib/maintain.js +++ b/lib/maintain.js @@ -9,8 +9,8 @@ function maintainCache() { // TODO i should check that im already running here and exit if i am console.log("Cache maintainence routine starting..."); for(var index in global.repoproxy.repo) { - console.log("start cleanup in ", index); - console.log("cleanup array ", global.repoproxy.repo[index]); + //console.log("start cleanup in ", index); + //console.log("cleanup array ", global.repoproxy.repo[index]); switch(global.repoproxy.repo[index]["type"]) { case "apt": console.log("Scanning '%s' as apt", index); @@ -22,6 +22,12 @@ function maintainCache() { case "yum": //console.log("Scanning '%s' as apt", index); //repoyum.maintain(global.repoproxy.repo[index]); + console.log("Scanning '%s' as yum", index); + var walkin = path.normalize(global.repoproxy.cacheDir + "/" + index); + walkDir(walkin, function(err, list) { + repoyum.maintain(index, global.repoproxy.repo[index], list); + }) + break; break; } } diff --git a/lib/repo-apt.js b/lib/repo-apt.js index fbe433e..de2c1c7 100644 --- a/lib/repo-apt.js +++ b/lib/repo-apt.js @@ -51,7 +51,7 @@ function maintain(name, repoinfo, files) { if(typeof files[0] != 'undefined') fileCheck(0) - else console.log("Skipping file check as there are none... apprently?"); + else console.log("Skipping (apt) file check as there are none... apprently?"); } exports.maintain = maintain; \ No newline at end of file diff --git a/lib/repo-yum.js b/lib/repo-yum.js index 18b383a..07a1893 100644 --- a/lib/repo-yum.js +++ b/lib/repo-yum.js @@ -1,5 +1,73 @@ -function maintain(details) { - console.log("doing yum clean for ", details); +var fs = require("fs"); +var http = require("http"); +var url = require("url"); +var path = require("path"); + + + +function maintain(name, repoinfo, files) { + console.log("doing yum clean for ", repoinfo); + + var metaAge = 24*3600*1000*(repoinfo.updateinterval); + var expireAge = 24*3600*1000*(repoinfo.expiretime); + + function fileCheck(i) { + console.log("checking file: ", files[i]); + + // we look for repodata/repomd.xml file, if this is past maturity, we clean that whole directory + if(files[i].match(/.*repodata\/repomd\.xml$/)) { + console.log("Found repomd.xml file: ", files[i]); + + // strip the repomd file to get the dir + var repomddir = files[i].replace(/repomd\.xml$/, ""); + console.log("repomd dir is:", repomddir); + + + // do the file stat + fs.stat(files[i], function(err, stats) { + console.log("stats for file was: ", stats); + var curtime = new Date().getTime(); + var ctime = stats.ctime.getTime(); + console.log("curtime is ", curtime); + console.log("ctime is ", ctime); + + var age = curtime - ctime; + console.log("age is (%d) for (%d)", age, metaAge); + if(age > metaAge) { + // TODO: cleanup repomd directory + } + }) + + } else { + // STUFF!!! + fs.stat(files[i], function(err, stats) { + console.log("stats for file was: ", stats); + var curtime = new Date().getTime(); + var atime = stats.atime.getTime(); + console.log("curtime is ", curtime); + console.log("ctime is ", atime); + + var age = curtime - atime; + console.log("age is (%d) for (%d)", age, expireAge); + if(age > expireAge) { + // TODO: cleanup singular file + // TODO: cleanup meta too, fuck me + console.log("clean up file \n", files[i]); + var metafile = files[i].replace(/(.*)\/(.[^\/]+$)/, "$1/.meta.$2.filesize"); + //console.log("meta for this file is \n", nfile); + fs.unlink(files[i]); + fs.unlink(metafile); + } + }) + } + + if(typeof files[i+1] != "undefined") fileCheck(i+1); + } + + if(typeof files[0] != 'undefined') fileCheck(0) + else console.log("Skipping (yum) file check as there are none... apprently?"); + + } exports.maintain = maintain; \ No newline at end of file