From 7d15a26e51a4aa2c5be0463c0fb3a6525c61cd0c Mon Sep 17 00:00:00 2001 From: tdurieux Date: Mon, 3 May 2021 14:52:42 +0200 Subject: [PATCH] protect stat call --- utils/file.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/utils/file.js b/utils/file.js index c427252..62cc097 100644 --- a/utils/file.js +++ b/utils/file.js @@ -20,15 +20,19 @@ async function walk(dir, root) { const output = { child: {} }; for (let file of files) { let filePath = path.join(dir, file); - const stats = await fs.stat(filePath); - if (file[0] == "$") { - file = "\\" + file; - } - if (stats.isDirectory()) { - output.child[file] = await walk(filePath, root); - output.child[file].sha = stats.ino; - } else if (stats.isFile()) { - output.child[file] = { size: stats.size, sha: stats.ino }; + try { + const stats = await fs.stat(filePath); + if (file[0] == "$") { + file = "\\" + file; + } + if (stats.isDirectory()) { + output.child[file] = await walk(filePath, root); + output.child[file].sha = stats.ino; + } else if (stats.isFile()) { + output.child[file] = { size: stats.size, sha: stats.ino }; + } + } catch (error) { + console.error(error); } } return output;