1 var fs = require("fs");
3 exports.loadConfig = function (conffile) {
5 global.repoproxy = new Object();
6 global.repoproxy.listenPort = 8008;
7 global.repoproxy.cacheDir = "./cache";
8 global.repoproxy.repo = new Object();
10 var confFileData = fs.readFileSync(conffile, "utf8");
12 // first split the file on carriage returns;
13 var confLines = confFileData.split("\n");
15 // go thru each line looking for config vars
16 for(var i=0; i<confLines.length; i++) {
19 var line_one = confLines[i].trim();
21 // split it up with :'s
22 var line_real = line_one.replace(/#.*/,"").split(":");
25 switch(line_real[0]) {
29 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]);
30 var thisrepo = { type : line_real[2], url: line_real[3]+":"+line_real[4], updateinterval: line_real[5], expiretime: line_real[6] };
31 global.repoproxy.repo[line_real[1]] = thisrepo;
35 console.log("Cache dir set to: ", line_real[1]);
36 global.repoproxy.cacheDir = line_real[1];
40 console.log("Port set to: ", line_real[1]);
41 global.repoproxy.listenPort = line_real[1];
44 if(line_real[0] != "") {
45 console.log("Invalid line in configuration file ignored: '%s'", line_one);
50 createCacheStructure();
54 function createCacheStructure() {
56 var state = fs.statSync(global.repoproxy.cacheDir);
57 //console.log("state is:", state);
60 fs.mkdirSync(global.repoproxy.cacheDir);
62 console.log("ERROR: failure to create cache directory, '%s'", global.repoproxy.cacheDir);
66 for(var index in global.repoproxy.repo) {
67 var fullDir = global.repoproxy.cacheDir + "/" + index;
69 var state = fs.statSync(global.repoproxy.cacheDir);
70 //console.log("state is:", state);
73 fs.mkdirSync(fullDir);
75 console.log("ERROR: failed to create cache directory, '%s' for '%s'", fullDir, index);