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) {
|
async function deleteFolderRecursive(folderPath) {
|
||||||
try {
|
try {
|
||||||
const files = await fs.promises.readdir(folderPath);
|
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 curPath = path.join(folderPath, file);
|
||||||
const stat = await fs.promises.lstat(curPath);
|
|
||||||
|
|
||||||
|
const stat = await fs.promises.lstat(curPath);
|
||||||
if (stat.isDirectory()) {
|
if (stat.isDirectory()) {
|
||||||
// recurse
|
// recurse
|
||||||
await deleteFolderRecursive(curPath);
|
return deleteFolderRecursive(curPath);
|
||||||
} else {
|
} else {
|
||||||
// delete file
|
// 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);
|
await fs.promises.rmdir(folderPath);
|
||||||
return files.length;
|
return files.length;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user