Skip to content

Commit 980e96a

Browse files
committedSep 25, 2022
fs: fix operation not permitted
fix: nodejs#44720 issue: - `copyDir()` calls `checkPathsSync()`, which invokes `lstat()` which causes error because of not checking the opts.filter changes: - check opts.filter before calling `checkPathsSync` and copy logic - cleanup `startCopy` function
1 parent a50e7c5 commit 980e96a

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, srcItem, destItem, opts);
290285
}
291286
} finally {
292287
dir.closeSync();

0 commit comments

Comments
 (0)
Please sign in to comment.