// 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);
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;
}
}
-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