mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 16:19:18 +00:00
🎈 perf: 优化清理文件性能
This commit is contained in:
parent
7385898f97
commit
10ee4155aa
@ -43,20 +43,20 @@ async function mkdirIfNotExists(dir) {
|
||||
async function deleteFolderRecursive(folderPath) {
|
||||
try {
|
||||
const files = await fs.promises.readdir(folderPath);
|
||||
const filePromises = files.map(async (file) => {
|
||||
const actions = files.map(async (file) => {
|
||||
const curPath = path.join(folderPath, file);
|
||||
const stat = await fs.promises.lstat(curPath);
|
||||
|
||||
const stat = await fs.promises.lstat(curPath);
|
||||
if (stat.isDirectory()) {
|
||||
// recurse
|
||||
await deleteFolderRecursive(curPath);
|
||||
return deleteFolderRecursive(curPath);
|
||||
} else {
|
||||
// delete file
|
||||
await fs.promises.unlink(curPath);
|
||||
return fs.promises.unlink(curPath);
|
||||
}
|
||||
});
|
||||
|
||||
await Promise.all(filePromises);
|
||||
await Promise.allSettled(actions);
|
||||
await fs.promises.rmdir(folderPath);
|
||||
return files.length;
|
||||
} catch (error) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user