1 var fs = require("fs");
2 var log = require("./log.js");
4 exports.loadConfig = function (conffile) {
6 global.repoproxy = new Object();
7 global.repoproxy.listenPort = 8008;
8 global.repoproxy.cacheDir = "./cache";
9 global.repoproxy.repo = new Object();
10 global.repoproxy.scancache = 1;
11 global.repoproxy.downloads = new Object();
12 global.repoproxy.loglevel = 3;
14 // set a global file id for file trashing
15 //global.repoproxy.fileid = new Object();
16 global.repoproxy.fileid = 1;
20 var confFileData = fs.readFileSync(conffile, "utf8");
22 // first split the file on carriage returns;
23 var confLines = confFileData.split("\n");
25 // go thru each line looking for config vars
26 for(var i=0; i<confLines.length; i++) {
29 var line_one = confLines[i].trim();
31 // split it up with :'s
32 var line_real = line_one.replace(/#.*/,"").split(":");
35 switch(line_real[0]) {
38 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]);
39 var thisrepo = { type : line_real[2], url: line_real[3]+":"+line_real[4], updateinterval: line_real[5], expiretime: line_real[6] };
40 global.repoproxy.repo[line_real[1]] = thisrepo;
44 var tmppath = line_real[1].replace(/\/+/g, "/");
45 log.info("Cache dir set to: ", tmppath);
46 global.repoproxy.cacheDir = tmppath;
50 log.info("Port set to: ", line_real[1]);
51 global.repoproxy.listenPort = line_real[1];
55 log.info("Set cache scan rate to: '%s' hours", line_real[1]);
56 global.repoproxy.scancache = parseInt(line_real[1]);
57 if(global.repoproxy.scancache == 0) {
58 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");
59 global.repoproxy.scancache = 24;
64 global.repoproxy.loglevel = parseInt(line_real[1]);
65 log.info("log level set to: ", global.repoproxy.loglevel);
69 if(line_real[0] != "") {
70 log.info("WARNING Invalid line in configuration file ignored: '%s'", line_one);
75 createCacheStructure();
76 //log.testLogSettings();
81 function createCacheStructure() {
83 var state = fs.statSync(global.repoproxy.cacheDir);
84 //log.info("state is:", state);
86 //log.info("try failure of cache dir stat ", e);
88 fs.mkdirSync(global.repoproxy.cacheDir);
90 log.error("failure to create cache directory, '%s'", global.repoproxy.cacheDir);
95 var state = fs.statSync(global.repoproxy.cacheDir + "/.cleanup");
96 //log.info("state is:", state);
99 fs.mkdirSync(global.repoproxy.cacheDir + "/.cleanup");
101 log.error("cant create cleanup directory, '%s'", global.repoproxy.cacheDir + "/.cleanup");
105 //log.info("next: ", global.repoproxy.repo);
106 for(var index in global.repoproxy.repo) {
107 var fullDir = global.repoproxy.cacheDir + "/" + index;
108 //log.info("on end, ", fullDir);
110 var state = fs.statSync(fullDir);
111 //log.info("state is:", state);
114 //log.info("attempted to create cache dir, ", fullDir);
115 fs.mkdirSync(fullDir);
117 log.error("failed to create cache directory, '%s' for '%s'", fullDir, index);