Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perf: copying dir contents in parallel #1026

Merged
merged 1 commit into from Nov 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/copy/copy.js
Expand Up @@ -113,21 +113,23 @@ async function onDir (srcStat, destStat, src, dest, opts) {
await fs.mkdir(dest)
}

const items = await fs.readdir(src)

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

// skip the item if it is matches by the filter function
const include = await runFilter(srcItem, destItem, opts)
if (!include) continue
if (!include) return

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

// If the item is a copyable file, `getStatsAndPerformCopy` will copy it
// If the item is a directory, `getStatsAndPerformCopy` will call `onDir` recursively
await getStatsAndPerformCopy(destStat, srcItem, destItem, opts)
}
return getStatsAndPerformCopy(destStat, srcItem, destItem, opts)
}))

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