-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Delete unused partitions on app start to free up space
- Loading branch information
1 parent
f385e80
commit 2586812
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
/** @typedef {import("../types").TabType} TabType */ | ||
|
||
/** | ||
* Deletes unused tab partitions to free up space | ||
* @param {TabType[]} tabs | ||
* @param {TabType} previouslyClosedTab | ||
* @param {string} userDataPath | ||
*/ | ||
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, | ||
}); | ||
}); | ||
}; | ||
|
||
module.exports = pruneUnusedPartitions; |