Skip to content

Commit d5455c6

Browse files
committed
fs.cp: fix operation not permitted
fix: nodejs#44720 issue: - [copyDir](https://github.com/nodejs/node/blob/7e0097d8a33fa7adbc1f298cbf647f6d2fd403e8/lib/internal/fs/cp/cp-sync.js#L287-L289) calls checkPathsSync(), which invokes lstat() which causes error because not checking the opts.filter changes: - check opts.filter before calling `checkPathsSync` and invoking copy logic - cleanup `startCopy` function
1 parent a50e7c5 commit d5455c6

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

lib/internal/fs/cp/cp-sync.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,6 @@ function handleFilterAndCopy(destStat, src, dest, opts) {
158158
return getStats(destStat, src, dest, opts);
159159
}
160160

161-
function startCopy(destStat, src, dest, opts) {
162-
if (opts.filter && !opts.filter(src, dest)) return;
163-
return getStats(destStat, src, dest, opts);
164-
}
165-
166161
function getStats(destStat, src, dest, opts) {
167162
const statSyncFn = opts.dereference ? statSync : lstatSync;
168163
const srcStat = statSyncFn(src);
@@ -284,9 +279,9 @@ function copyDir(src, dest, opts) {
284279
const { name } = dirent;
285280
const srcItem = join(src, name);
286281
const destItem = join(dest, name);
282+
if (opts.filter && !opts.filter(srcItem, destItem)) continue;
287283
const { destStat } = checkPathsSync(srcItem, destItem, opts);
288-
289-
startCopy(destStat, srcItem, destItem, opts);
284+
getStats(destStat, src, dest, opts);
290285
}
291286
} finally {
292287
dir.closeSync();

0 commit comments

Comments
 (0)