X-Git-Url: http://git.pjr.cc/?p=nodejs-repoproxy.git;a=blobdiff_plain;f=lib%2Fconfig.js;h=8d6d2fcf8226e69df026c462630e735f0b7d9ed2;hp=dd13be4da4478ac844938be415b20df78009d0d6;hb=d7478970127408f056b157f18df74fef7db3f892;hpb=c3e6676d533e875b020d231075aac04e4b885677 diff --git a/lib/config.js b/lib/config.js index dd13be4..8d6d2fc 100644 --- a/lib/config.js +++ b/lib/config.js @@ -1,4 +1,5 @@ var fs = require("fs"); +var log = require("./log.js"); exports.loadConfig = function (conffile) { @@ -6,7 +7,14 @@ exports.loadConfig = function (conffile) { global.repoproxy.listenPort = 8008; global.repoproxy.cacheDir = "./cache"; global.repoproxy.repo = new Object(); - global.repoproxy.scancache = 1; + global.repoproxy.scancache = 1; + global.repoproxy.downloads = new Object(); + + // set a global file id for file trashing + //global.repoproxy.fileid = new Object(); + global.repoproxy.fileid = 1; + + var confFileData = fs.readFileSync(conffile, "utf8"); @@ -33,9 +41,9 @@ 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]); @@ -49,6 +57,10 @@ exports.loadConfig = function (conffile) { global.repoproxy.scancache = 24; } break; + case "loggerlevel": + global.repoproxy.loglevel = parseInt(line_real[1]); + console.log("log level set to: ", global.repoproxy.loglevel); + break; default: if(line_real[0] != "") { console.log("WARNING Invalid line in configuration file ignored: '%s'", line_one); @@ -57,14 +69,17 @@ exports.loadConfig = function (conffile) { } createCacheStructure(); + log.testLogSettings(); } + function createCacheStructure() { try { var state = fs.statSync(global.repoproxy.cacheDir); //console.log("state is:", state); } catch(e) { + //console.log("try failure of cache dir stat ", e); try { fs.mkdirSync(global.repoproxy.cacheDir); } catch(ex) { @@ -72,13 +87,27 @@ function createCacheStructure() { } } + try { + var state = fs.statSync(global.repoproxy.cacheDir + "/.cleanup"); + //console.log("state is:", state); + } catch(e) { + 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); + 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);