Skip to content

Commit

Permalink
fix: Check first whether Partitions dir exists
Browse files Browse the repository at this point in the history
  • Loading branch information
amanharwara committed Nov 15, 2021
1 parent 631d11c commit b4d2020
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/util/pruneUnusedPartitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit b4d2020

Please sign in to comment.