trying to find out whats causing an occasional crash
[nodejs-repoproxy.git] / lib / cache.js
index e065a2a..3e9ec77 100644 (file)
@@ -15,7 +15,7 @@ exports.startTimer = function() {
        setInterval(maintainCache, cacheTimer);
 }
 
-function upstreamRequest(unify, callback) {
+function upstreamRequest(unify) {
        // first do a head request
        console.log("upsteram as ", unify.requestFor);
        
@@ -98,8 +98,9 @@ exports.upstreamRequest = upstreamRequest;
 
 function getAndService(unify, xpath) {
        
-       if(global.repoproxy.downloads[unify.fullFilePath] == 1) {
+       if(typeof global.repoproxy.downloads[unify.fullFilePath] != "undefined" && global.repoproxy.downloads[unify.fullFilePath] == 1) {
                
+               console.log("service inline");
                unify.b.write("trying to service inline");
                unify.b.end();
        } else {
@@ -125,6 +126,10 @@ function getAndService(unify, xpath) {
                            file.end();
                            global.repoproxy.downloads[unify.fullFilePath] = 0;
                    });
+                   
+                   res.on("error", function(err) {
+                       console.log("res threw error... ", err);
+                   });
                });
        }
 }
@@ -136,7 +141,7 @@ function serviceFile(unify) {
 
        // file should already exist, so we just poop it out
        var inp = fs.createReadStream(unify.fullFilePath);
-       inp.setEncoding("utf8");
+       //inp.setEncoding("utf8");
        inp.on("data", function(data) {
                unify.b.write(data);
        });
@@ -170,7 +175,7 @@ function serviceDirectory(unify) {
        var res = unify.b;
        
        res.write("<html><h1>Directory listing for " + unify.originalReq + "</h1><hr><pre>");
-       if(unify.fullFilePath != "/") res.write("<a href=\"..\">Parent</a>\n\n");
+       if(unify.originalReq != "/") res.write("<a href=\"..\">Parent</a>\n\n");
        fs.readdir(unify.fullFilePath, function(err, files) {
                console.log("doing directory listing on: ", unify.fullFilePath);
                if(err == null) {