Skip to content

Commit

Permalink
refactor: replace readdir w/ opendir
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Nov 28, 2023
1 parent 53f49d1 commit 43c99dc
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,20 @@ const rcpy = async (src: string, dest: string, opt: RcpyOption = {}): Promise<vo
await fsp.mkdir(dest);
}

const items = await fsp.readdir(src);
const promises: Array<Promise<void>> = [];

await Promise.all(items.map(async item => {
const srcItem = path.join(src, item);
const destItem = path.join(dest, item);
for await (const item of await fsp.opendir(src)) {
const srcItem = path.join(src, item.name);
const destItem = path.join(dest, item.name);

if (!(await filter(srcItem, destItem))) {
return;
continue;
}

return performCopy(srcItem, destItem, await checkPaths(srcItem, destItem, _opt.dereference));
}));
promises.push(performCopy(srcItem, destItem, await checkPaths(srcItem, destItem, _opt.dereference)));
}

await Promise.all(promises);

if (!destStat) {
await fsp.chmod(dest, srcStat.mode);
Expand Down

0 comments on commit 43c99dc

Please sign in to comment.