X-Git-Url: http://git.pjr.cc/?p=nodejs-repoproxy.git;a=blobdiff_plain;f=lib%2Fconfig.js;h=8af15f003f71a79527a7a5f94a36b76dedd643b9;hp=dd13be4da4478ac844938be415b20df78009d0d6;hb=3933776341028e83d89e0f888fff3e6319230abf;hpb=c3e6676d533e875b020d231075aac04e4b885677 diff --git a/lib/config.js b/lib/config.js index dd13be4..8af15f0 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,15 @@ 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(); + global.repoproxy.loglevel = 3; + + // set a global file id for file trashing + //global.repoproxy.fileid = new Object(); + global.repoproxy.fileid = 1; + + var confFileData = fs.readFileSync(conffile, "utf8"); @@ -25,63 +34,87 @@ exports.loadConfig = function (conffile) { // parse the line switch(line_real[0]) { case "repo": - // TODO: VALIDATE! - console.log("Adding repo: '/%s' type '%s' from '%s', with update interval of '%s' days, and expire time of '%s' days.", line_real[1], line_real[2], line_real[3]+":"+line_real[4], line_real[5], line_real[6]); + log.info("Adding repo: '/%s' type '%s' from '%s', with update interval of '%s' days, and expire time of '%s' days.", line_real[1], line_real[2], line_real[3]+":"+line_real[4], line_real[5], line_real[6]); var thisrepo = { type : line_real[2], url: line_real[3]+":"+line_real[4], updateinterval: line_real[5], expiretime: line_real[6] }; global.repoproxy.repo[line_real[1]] = thisrepo; - break; - case "cachedir": - console.log("Cache dir set to: ", line_real[1]); - global.repoproxy.cacheDir = line_real[1]; + case "cachedir": + var tmppath = line_real[1].replace(/\/+/g, "/"); + log.info("Cache dir set to: ", tmppath); + global.repoproxy.cacheDir = tmppath; break; + case "listenport": - console.log("Port set to: ", line_real[1]); + log.info("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]); + log.info("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"); + log.info("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; + + case "loggerlevel": + global.repoproxy.loglevel = parseInt(line_real[1]); + log.info("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); + log.info("WARNING Invalid line in configuration file ignored: '%s'", line_one); } } } createCacheStructure(); + //log.testLogSettings(); } + function createCacheStructure() { try { var state = fs.statSync(global.repoproxy.cacheDir); - //console.log("state is:", state); + //log.info("state is:", state); } catch(e) { + //log.info("try failure of cache dir stat ", e); try { fs.mkdirSync(global.repoproxy.cacheDir); } catch(ex) { - console.log("ERROR: failure to create cache directory, '%s'", global.repoproxy.cacheDir); + log.error("failure to create cache directory, '%s'", global.repoproxy.cacheDir); + } + } + + try { + var state = fs.statSync(global.repoproxy.cacheDir + "/.cleanup"); + //log.info("state is:", state); + } catch(e) { + try { + fs.mkdirSync(global.repoproxy.cacheDir + "/.cleanup"); + } catch(ex) { + log.error("cant create cleanup directory, '%s'", global.repoproxy.cacheDir + "/.cleanup"); } } + //log.info("next: ", global.repoproxy.repo); for(var index in global.repoproxy.repo) { var fullDir = global.repoproxy.cacheDir + "/" + index; + //log.info("on end, ", fullDir); try { - var state = fs.statSync(global.repoproxy.cacheDir); - //console.log("state is:", state); + var state = fs.statSync(fullDir); + //log.info("state is:", state); } catch(e) { try { + //log.info("attempted to create cache dir, ", fullDir); fs.mkdirSync(fullDir); } catch(ex) { - console.log("ERROR: failed to create cache directory, '%s' for '%s'", fullDir, index); + log.error("failed to create cache directory, '%s' for '%s'", fullDir, index); } } }