From b4d202045f9c4019cc2cd6b8fb4f15631c7a851b Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Mon, 15 Nov 2021 17:50:15 +0530 Subject: [PATCH] fix: Check first whether Partitions dir exists --- src/util/pruneUnusedPartitions.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/util/pruneUnusedPartitions.js b/src/util/pruneUnusedPartitions.js index c01292f7..0e55fd4a 100644 --- a/src/util/pruneUnusedPartitions.js +++ b/src/util/pruneUnusedPartitions.js @@ -11,21 +11,23 @@ const path = require("path"); */ const pruneUnusedPartitions = (tabs, previouslyClosedTab, userDataPath) => { const partitionsDirPath = path.join(userDataPath, "Partitions"); - const partitions = fs.readdirSync(partitionsDirPath); - const tabIds = []; - tabs.forEach((tab) => { - tabIds.push(tab.id); - }); - if (previouslyClosedTab) { - tabIds.push(previouslyClosedTab.id); - } - partitions - .filter((id) => !tabIds.includes(id)) - .forEach((partition) => { - fs.rmSync(path.join(partitionsDirPath, partition), { - recursive: true, - }); + if (fs.existsSync(partitionsDirPath)) { + const partitions = fs.readdirSync(partitionsDirPath); + const tabIds = []; + tabs.forEach((tab) => { + tabIds.push(tab.id); }); + if (previouslyClosedTab) { + tabIds.push(previouslyClosedTab.id); + } + partitions + .filter((id) => !tabIds.includes(id)) + .forEach((partition) => { + fs.rmSync(path.join(partitionsDirPath, partition), { + recursive: true, + }); + }); + } }; module.exports = pruneUnusedPartitions;