Skip to content

Commit d293448

Browse files
authoredNov 28, 2023
perf: copy dir contents in parallel (#1026)
1 parent a277cbb commit d293448

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed
 

‎lib/copy/copy.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -113,21 +113,23 @@ async function onDir (srcStat, destStat, src, dest, opts) {
113113
await fs.mkdir(dest)
114114
}
115115

116+
const items = await fs.readdir(src)
117+
116118
// loop through the files in the current directory to copy everything
117-
for (const item of await fs.readdir(src)) {
119+
await Promise.all(items.map(async item => {
118120
const srcItem = path.join(src, item)
119121
const destItem = path.join(dest, item)
120122

121123
// skip the item if it is matches by the filter function
122124
const include = await runFilter(srcItem, destItem, opts)
123-
if (!include) continue
125+
if (!include) return
124126

125127
const { destStat } = await stat.checkPaths(srcItem, destItem, 'copy', opts)
126128

127129
// If the item is a copyable file, `getStatsAndPerformCopy` will copy it
128130
// If the item is a directory, `getStatsAndPerformCopy` will call `onDir` recursively
129-
await getStatsAndPerformCopy(destStat, srcItem, destItem, opts)
130-
}
131+
return getStatsAndPerformCopy(destStat, srcItem, destItem, opts)
132+
}))
131133

132134
if (!destStat) {
133135
await fs.chmod(dest, srcStat.mode)

0 commit comments

Comments
 (0)
Please sign in to comment.