From 6f93a4a8c5accb4ecb2e66e1cd19ef4e586a8a4a Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Mon, 31 Aug 2020 17:46:33 +0000 Subject: [ipxe builder] Add try-catch when reading the builds directory --- server/lib/shell.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'server/lib') diff --git a/server/lib/shell.js b/server/lib/shell.js index 29986de..4f315e4 100644 --- a/server/lib/shell.js +++ b/server/lib/shell.js @@ -122,13 +122,17 @@ module.exports = { readdirRecursive: function (buildsPath) { let structure = [] - const directory = fs.readdirSync(buildsPath) - for (let obj of directory) { - if (!fs.lstatSync(path.join(buildsPath, obj)).isDirectory()) { - structure.push({ name: obj, type: 'file' }) - } else { - structure.push({ name: obj, type: 'directory', children: this.readdirRecursive(path.join(buildsPath, obj)) }) + try { + const directory = fs.readdirSync(buildsPath) + for (let obj of directory) { + if (!fs.lstatSync(path.join(buildsPath, obj)).isDirectory()) { + structure.push({ name: obj, type: 'file' }) + } else { + structure.push({ name: obj, type: 'directory', children: this.readdirRecursive(path.join(buildsPath, obj)) }) + } } + } catch (error) { + return [] } return structure }, -- cgit v1.2.3-55-g7522