From 724a120f06570841c2c2faaf710d329551e397b3 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Wed, 1 Mar 2017 15:51:41 +0100 Subject: Fix broken symlinks in listing --- webserver.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/webserver.js b/webserver.js index 84864cd..3e18b4d 100755 --- a/webserver.js +++ b/webserver.js @@ -7,6 +7,7 @@ var app=require("express")(), url=require("url"), fs=require("fs"), util=require("util"), + node_path=require("path"), bodyParser=require("body-parser"), basicAuth=require("basic-auth"); @@ -61,12 +62,20 @@ function requestFile(req,res,path){ var stats=fs.statSync(fname); if(stats.isFile())res.sendFile(fname); else if(stats.isDirectory()){ - var items=fs.readdirSync(fname) - .filter(function(f){return f[0]!=".";}) - .map(function(f){ - if(fs.statSync(fname+"/"+f).isDirectory())return f+"/"; - else return f; - }); + var items=fs + .readdirSync(fname) + .filter(function(f){return f[0]!=".";}) + .map(function(f){ + try { + if(fs.statSync(node_path.join(fname,f)).isDirectory())return f+"/"; + else return f; + } catch(e){ + return null; + } + }) + .filter(function(f){ + return f!==null; + }); res.send( String(fs.readFileSync(cmn.rootdir+"/web_files/dirlisting.html")) .replace("",path) -- cgit v1.2.3-70-g09d2