upstream now appears to work just fine
[nodejs-repoproxy.git] / lib / config.js
index 8d5de4b..7cab68a 100644 (file)
@@ -6,6 +6,8 @@ exports.loadConfig = function (conffile) {
        global.repoproxy.listenPort = 8008;
        global.repoproxy.cacheDir = "./cache";
        global.repoproxy.repo = new Object();
+       global.repoproxy.scancache = 1;
+       global.repoproxy.downloads = new Object();
        
        var confFileData = fs.readFileSync(conffile, "utf8");
        
@@ -32,17 +34,25 @@ exports.loadConfig = function (conffile) {
                        
                        break;
                case "cachedir":
-                       console.log("Cache dir set to: ", line_real[1]);
-                       global.repoproxy.cacheDir = line_real[1];
-                       
+                       var tmppath = line_real[1].replace(/\/+/g, "/");
+                       console.log("Cache dir set to: ", tmppath);
+                       global.repoproxy.cacheDir = tmppath;
                        break;
                case "listenport":
                        console.log("Port set to: ", line_real[1]);
                        global.repoproxy.listenPort = line_real[1];
                        break;
+               case "cachescan":
+                       console.log("Set cache scan rate to: '%s' hours", line_real[1]);
+                       global.repoproxy.scancache = parseInt(line_real[1]);
+                       if(global.repoproxy.scancache == 0) {
+                               console.log("Cache scan rate didnt make sense, it was 0, and should be at least 1 - it is set to 24, but you should check this setting");
+                               global.repoproxy.scancache = 24;
+                       }
+                       break;
                default:
                        if(line_real[0] != "") {
-                               console.log("Invalid line in configuration file ignored: '%s'", line_one);
+                               console.log("WARNING Invalid line in configuration file ignored: '%s'", line_one);
                        }
                }
        }
@@ -58,18 +68,28 @@ function createCacheStructure() {
        } catch(e) {
                try {
                        fs.mkdirSync(global.repoproxy.cacheDir);
+                       fs.mkdirSync(global.repoproxy.cacheDir + "/.cleanup");
                } catch(ex) {
                        console.log("ERROR: failure to create cache directory, '%s'", global.repoproxy.cacheDir);
                }
        }
        
+       try {
+               fs.mkdirSync(global.repoproxy.cacheDir + "/.cleanup");
+       } catch(ex) {
+               console.log("ERROR: cant create cleanup directory, '%s'", global.repoproxy.cacheDir + "/.cleanup");
+       }
+       
+       console.log("next: ", global.repoproxy.repo);
        for(var index in global.repoproxy.repo) {
                var fullDir = global.repoproxy.cacheDir + "/" + index;
+               console.log("on end, ", fullDir);
                try {
-                       var state = fs.statSync(global.repoproxy.cacheDir);
-                       //console.log("state is:", state);
+                       var state = fs.statSync(fullDir);
+                       console.log("state is:", state);
                } catch(e) {
                        try {
+                               console.log("attempted to create cache dir, ", fullDir);
                                fs.mkdirSync(fullDir);
                        } catch(ex) {
                                console.log("ERROR: failed to create cache directory, '%s' for '%s'", fullDir, index);