diff --git a/lib/core/show-dir/index.js b/lib/core/show-dir/index.js index d2ece8ec5..001e41a2c 100644 --- a/lib/core/show-dir/index.js +++ b/lib/core/show-dir/index.js @@ -73,11 +73,11 @@ module.exports = (opts) => { res.setHeader('etag', etag(stat, weakEtags)); res.setHeader('last-modified', (new Date(stat.mtime)).toUTCString()); res.setHeader('cache-control', cache); - + // A step before render() is called to gives items additional // information so that render() can deliver the best user experience // possible. - function process(dirs, renderFiles, lolwuts) { + function prerender(dirs, renderFiles, errs) { const filenamesThatExist = new Set(); // Putting filenames in a set first keeps us in O(n) time complexity @@ -87,7 +87,7 @@ module.exports = (opts) => { const renderOptions = {}; renderFiles[i] = [name, stat, renderOptions]; } - + // Set render options for compressed files for (const [name, _stat, renderOptions] of renderFiles) { if ( @@ -115,10 +115,10 @@ module.exports = (opts) => { renderOptions.uncompressedName = uncompressedName; } } - render(dirs, renderFiles, lolwuts); + render(dirs, renderFiles, errs); } - function render(dirs, renderFiles, lolwuts) { + function render(dirs, renderFiles, errs) { // each entry in the array is a [name, stat] tuple let html = `${[ @@ -150,7 +150,7 @@ module.exports = (opts) => { // Handle compressed files with uncompressed names let displayNameHTML; let fileSize = sizeToString(file[1], humanReadable, si); - + if (file[2] && file[2].uncompressedName) { // This is a compressed file, show both names with separate links const uncompressedName = he.encode(file[2].uncompressedName); @@ -184,7 +184,7 @@ module.exports = (opts) => { dirs.sort((a, b) => a[0].toString().localeCompare(b[0].toString())).forEach(writeRow); renderFiles.sort((a, b) => a.toString().localeCompare(b.toString())).forEach(writeRow); - lolwuts.sort((a, b) => a[0].toString().localeCompare(b[0].toString())).forEach(writeRow); + errs.sort((a, b) => a[0].toString().localeCompare(b[0].toString())).forEach(writeRow); html += '\n'; html += `
Node.js ${ @@ -201,7 +201,7 @@ module.exports = (opts) => { } } - sortFiles(dir, files, (lolwuts, dirs, sortedFiles) => { + sortFiles(dir, files, (errs, dirs, sortedFiles) => { // It's possible to get stat errors for all sorts of reasons here. // Unfortunately, our two choices are to either bail completely, // or just truck along as though everything's cool. In this case, @@ -222,10 +222,10 @@ module.exports = (opts) => { return; } dirs.unshift(['..', s]); - process(dirs, sortedFiles, lolwuts); + prerender(dirs, sortedFiles, errs); }); } else { - process(dirs, sortedFiles, lolwuts); + prerender(dirs, sortedFiles, errs); } }); }); diff --git a/lib/core/show-dir/last-modified-to-string.js b/lib/core/show-dir/last-modified-to-string.js index 917d38010..856236c3e 100644 --- a/lib/core/show-dir/last-modified-to-string.js +++ b/lib/core/show-dir/last-modified-to-string.js @@ -1,6 +1,10 @@ 'use strict'; module.exports = function lastModifiedToString(stat) { + if (!stat.mtime) { + // stat error (eg, broken symlink) + return 'Unknown Date'; + } const t = new Date(stat.mtime); return (('0' + (t.getDate())).slice(-2) + '-' + t.toLocaleString('default', { month: 'short' }) + '-' + diff --git a/lib/core/show-dir/perms-to-string.js b/lib/core/show-dir/perms-to-string.js index 9e65821d7..c0711f792 100644 --- a/lib/core/show-dir/perms-to-string.js +++ b/lib/core/show-dir/perms-to-string.js @@ -2,7 +2,7 @@ module.exports = function permsToString(stat) { if (!stat.isDirectory || !stat.mode) { - return '???!!!???'; + return '????!!!???'; } const dir = stat.isDirectory() ? 'd' : '-';