Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fs: fix operation not permitted
fix: #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
  • Loading branch information
thoqbk committed Sep 25, 2022
commit 980e96afe468adeeb6312a0eaa1501289add3821
9 changes: 2 additions & 7 deletions lib/internal/fs/cp/cp-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,6 @@ function handleFilterAndCopy(destStat, src, dest, opts) {
return getStats(destStat, src, dest, opts);
}

function startCopy(destStat, src, dest, opts) {
if (opts.filter && !opts.filter(src, dest)) return;
return getStats(destStat, src, dest, opts);
}

function getStats(destStat, src, dest, opts) {
const statSyncFn = opts.dereference ? statSync : lstatSync;
const srcStat = statSyncFn(src);
Expand Down Expand Up @@ -284,9 +279,9 @@ function copyDir(src, dest, opts) {
const { name } = dirent;
const srcItem = join(src, name);
const destItem = join(dest, name);
if (opts.filter && !opts.filter(srcItem, destItem)) continue;
const { destStat } = checkPathsSync(srcItem, destItem, opts);

startCopy(destStat, srcItem, destItem, opts);
getStats(destStat, srcItem, destItem, opts);
}
} finally {
dir.closeSync();
Expand Down