-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