added a logger, started working on the maintenance timer routines
[nodejs-repoproxy.git] / lib / cache.js
index 9e5e8da..588bc73 100644 (file)
@@ -2,19 +2,7 @@ var fs = require("fs");
 var http = require("http");
 var url = require("url");
 var path = require("path");
-
-function maintainCache() {
-       // TODO i should check that im already running here and exit if i am
-       console.log("Cache maintainence routine starting...");
-       console.log("Cache maintainence routine ended...");
-}
-
-exports.startTimer = function() {
-       // our once-a-day cache maintainer
-       var cacheTimer = global.repoproxy.scancache*3600*1000;
-       //var cacheTimer = global.repoproxy.scancache*100;
-       setInterval(maintainCache, cacheTimer);
-}
+var crypto = require("crypto");
 
 function upstreamRequest(unify) {
        // first do a head request
@@ -345,4 +333,22 @@ function serviceDirectory(unify) {
        });
 }
 
-exports.serviceDirectory = serviceDirectory;
\ No newline at end of file
+function moveToCleanup(file_or_dir) {
+       // err..?
+       var cleanup = global.repoproxy.cacheDir + "/.cleanup";
+       var ctime = new Date().getTime();
+       var encoded = (++global.repoproxy.fileid).toString();
+       var toloc = cleanup + "/" + ctime.toString() + "." + encoded;
+       
+       //console.log("Moving %s to %s for cleanup", file_or_dir.replace(/\/$/, ""), toloc);
+       
+       fs.renameSync(file_or_dir.replace(/\/$/, ""), toloc);
+}
+
+function cleanupRoutine() {
+       
+}
+
+
+exports.serviceDirectory = serviceDirectory;
+exports.moveToCleanup = moveToCleanup;