expressjs / serve-index

Serve directory listings

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot stat `System Volume Information` sub dir on a root drive on Windows 10

chenzx opened this issue · comments

When i use it to index my root drive g:/ on Windows 10, an error occurs:

Error: EPERM: operation not permitted, stat 'g:\System Volume Information'
    at Error (native)

even i add filter option to bypass, it is still not working:

var urlPath_to_rootDrive_Mapping = {
    "/c": "c:/",
    "/d": "d:/",
    "/e": "e:/",
    "/f": "f:/",
    "/g": "g:/",
    "/h": "h:/",
    "/": "d:/"
};
for(var urlPath in urlPath_to_rootDrive_Mapping){
    var rootDrive = urlPath_to_rootDrive_Mapping[urlPath];
    console.log("map "+urlPath+"/* --> " + rootDrive);
    app.use(urlPath, serveIndex(rootDrive, {
        'icons': true,
        'filter': function(filename, index, files, dir){
            console.log("filename="+filename);
            if(filename=="System Volume Information"){
                console.log("HIT "+filename);
                return true;
            }
            return false;
        }
        })
    )
    var serve = serveStatic(rootDrive)
    app.get(urlPath+'/*', function(req, res){
        req.url = req.url.substring(2);
        console.log("["+req.request_id+"] GET static "+req.url);
        serve(req, res)
    });
}

Maybe i just didn't fully understand the code, please fix this, thanks!

Hi, i mis-understand the document.
The page says 'filter' defaults to return false, so i thought return false means to keep the file.
The working code(although dirty):

    app.use(urlPath, serveIndex(rootDrive, {
        'icons': true,
        'filter': function(filename, index, files, dir){
            console.log("filename="+filename);
            if(filename=="System Volume Information"){
                console.log("HIT "+filename);
                return false;
            }
            return true;
        }
        })
    )