X-Git-Url: http://git.pjr.cc/?p=nodejs-repoproxy.git;a=blobdiff_plain;f=lib%2Frepo-apt.js;fp=lib%2Frepo-apt.js;h=07248a06a0a28d6087f84d9f5405f65d5f80ce51;hp=f37f8816424bc40e35d7f0c5a5b8c4468c5e2de6;hb=85fcaedb62209c356da64b865f981d212ae593d4;hpb=04f3190a0bcc430af31917456a957ecc80eb160b diff --git a/lib/repo-apt.js b/lib/repo-apt.js index f37f881..07248a0 100644 --- a/lib/repo-apt.js +++ b/lib/repo-apt.js @@ -1,5 +1,55 @@ -function maintain(details) { - console.log("doing apt 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 apt clean for ", repoinfo); + + var topdir = path.normalize(global.repoproxy.cacheDir + "/" + name + "/"); + + function fileCheck(i) { + //console.log("checking file: ", files[i]); + + var cfile = files[i].replace(topdir, ""); + var ctime_t = new Date(); + var ctime = ctime_t.getTime(); + var time_ui = ((ctime) - ((repoinfo["updateinterval"] * 3600 * 24 * 1000) - (12*3600*1000))); + var time_et = ((ctime) - ((repoinfo["expiretime"] * 3600 * 24 * 1000) - (12*3600*1000))); + + // file checks go here + if(typeof global.repoproxy.downloads[files[i]] != "undefined" && global.repoproxy.downloads[files[i]] == 1) { + // ignore this file as its being downloaded + console.log("not checking file because its downloading ", cfile); + if(typeof files[i+1] != "undefined") fileCheck(i+1); + } else { + fs.stat(files[i], function(err, stats) { + + //console.log("deep check", cfile); + if(cfile.match(/.*dists\/.*/) != null) { + // its a dist file, probably, check age and erase if necessary + if(stats["mtime"].getTime() < time_ui) { + // erase file + console.log("unlinking file for time_ui: ", files[i]) + //fs.unlink(files[i]); + } else { + //console.log("times for file '%s', '%s', '%s', '%s'", cfile, time_ui, time_et, stats["mtime"].getTime()); + } + + } else { + // its just some other file, check the read time + if(stats["atime"].getTime() < time_et) { + console.log("unlinking file for time_et: ", files[i]); + } + } + if(typeof files[i+1] != "undefined") fileCheck(i+1); + }); + } + + + } + + fileCheck(0) } exports.maintain = maintain; \ No newline at end of file