1 var fs = require("fs");
2 var http = require("http");
3 var url = require("url");
4 var path = require("path");
6 function maintain(name, repoinfo, files) {
7 //console.log("doing apt clean for ", repoinfo);
9 var topdir = path.normalize(global.repoproxy.cacheDir + "/" + name + "/");
11 function fileCheck(i) {
12 console.log("checking file: ", files[i]);
14 var cfile = files[i].replace(topdir, "");
15 var ctime_t = new Date();
16 var ctime = ctime_t.getTime();
17 var time_ui = ((ctime) - ((repoinfo["updateinterval"] * 3600 * 24 * 1000) - (12*3600*1000)));
18 var time_et = ((ctime) - ((repoinfo["expiretime"] * 3600 * 24 * 1000) - (12*3600*1000)));
20 // file checks go here
21 if(typeof global.repoproxy.downloads[files[i]] != "undefined" && global.repoproxy.downloads[files[i]] == 1) {
22 // ignore this file as its being downloaded
23 console.log("not checking file because its downloading ", cfile);
24 if(typeof files[i+1] != "undefined") fileCheck(i+1);
26 fs.stat(files[i], function(err, stats) {
28 //console.log("deep check", cfile);
29 if(cfile.match(/.*dists\/.*/) != null) {
30 // its a dist file, probably, check age and erase if necessary
31 if(stats["mtime"].getTime() < time_ui) {
33 console.log("unlinking file for time_ui: ", files[i])
34 //fs.unlink(files[i]);
36 //console.log("times for file '%s', '%s', '%s', '%s'", cfile, time_ui, time_et, stats["mtime"].getTime());
40 // its just some other file, check the read time
41 if(stats["atime"].getTime() < time_et) {
42 console.log("unlinking file for time_et: ", files[i]);
45 if(typeof files[i+1] != "undefined") fileCheck(i+1);
53 if(typeof files[0] != 'undefined') fileCheck(0)
54 else console.log("Skipping (apt) file check as there are none... apprently?");
57 exports.maintain = maintain;