-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
fs: fix operation not permitted #44786
Conversation
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you include a test?
test was added |
filter: path => !path.includes('foo'), | ||
recursive: true, | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before fixing, when I run this test it throws the following error because checkPathsSync(srcItem, destItem, opts)
gets called even though the srcItem
shouldn't be copied:
SystemError [ERR_FS_CP_DIR_TO_NON_DIR]: Cannot overwrite directory with non-directory: cp returned EISDIR (cannot overwrite directory /Users/xxx/dev/node/test/.tmp.0/copy_28/foo with non-directory /Users/xxx/dev/node/test/.tmp.0/copy_29/foo) /Users/xxx/dev/node/test/.tmp.0/copy_29/foo
at new SystemError (node:internal/errors:244:5)
at new NodeError (node:internal/errors:355:7)
at checkPathsSync (node:internal/fs/cp/cp-sync:77:13)
at copyDir (node:internal/fs/cp/cp-sync:287:28)
at onDir (node:internal/fs/cp/cp-sync:268:10)
at getStats (node:internal/fs/cp/cp-sync:171:12)
at handleFilterAndCopy (node:internal/fs/cp/cp-sync:158:10)
at cpSyncFn (node:internal/fs/cp/cp-sync:60:10)
at cpSync (node:fs:2899:3)
at file:///Users/xxx/dev/node/test/parallel/test-fs-cp.mjs:353:3 {
code: 'ERR_FS_CP_DIR_TO_NON_DIR',
info: {
message: 'cannot overwrite directory /Users/xxx/dev/node/test/.tmp.0/copy_28/foo with non-directory /Users/xxx/dev/node/test/.tmp.0/copy_29/foo',
path: '/Users/xxx/dev/node/test/.tmp.0/copy_29/foo',
syscall: 'cp',
errno: 21,
code: 'EISDIR'
},
errno: [Getter/Setter],
syscall: [Getter/Setter],
path: [Getter/Setter]
}
4c84e46
to
aa3e4f1
Compare
test/parallel/test-fs-cp.mjs
Outdated
// It should not throw exception if child folder | ||
// does not pass filter function | ||
{ | ||
// Mimic there's a file in dest with the same name as the child folder in src |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The start of this sentence is a bit awkward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
aa3e4f1
to
ec30bf0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a nit to clarify the comments.
Co-authored-by: Joyee Cheung <[email protected]>
Rework PR #45143 |
fix: #44720
issue:
copyDir()
callscheckPathsSync()
, which invokeslstat()
causes error because of not checking the opts.filter
changes:
checkPathsSync
and copy logicstartCopy
function