fs: fs.cp() should accept mode flag to specify the copy behavior#47084
Conversation
|
cc @nodejs/fs |
3579490 to
1b4e164
Compare
| assertDirEquivalent(src, dest); | ||
| // If the platform support `COPYFILE_FICLONE_FORCE` operation, | ||
| // it should reach to here. | ||
| } catch (err) { |
There was a problem hiding this comment.
This catch block also catches assertDirEquivalent failures, doesn't it? Better to move that outside the block.
(Also applies to code further below.)
There was a problem hiding this comment.
This catch block also catches assertDirEquivalent failures, doesn't it?
Yes, it is. I addressed them in 3451bbe.
|
@bnoordhuis How about this? Could you review this again? |
|
@nodejs/fs Could you review this? |
|
@tetsuharuohzeki my comment was a drive-by thing, just something I noticed. I'll leave signing off on the main change to @nodejs/fs. |
3451bbe to
34dc434
Compare
|
I rebased this on the latest main. |
|
Can you amend the commit message so it matches our commit message guidelines? node/doc/contributing/pull-requests.md Lines 168 to 169 in 5af2021 E.g. |
34dc434 to
fc8eafe
Compare
|
Thank you for your review! I addressed my patch. |
fc8eafe to
1f6dfc4
Compare
`fs.copyFile()` supports copy-on-write operation if the underlying platform supports it by passing a mode flag. This behavior was added in nodejs@a16d88d. This patch adds `mode` flag to `fs.cp()`, `fs.cpSync()`, and `fsPromises.cp()` to allow to change their behaviors to copy files. This test case is based on the test case that was introduced when we add `fs.constants.COPYFILE_FICLONE`. nodejs@a16d88d. This test strategy is: - If the platform supports copy-on-write operation, check whether the destination is expected - Otherwise, the operation will fail and check whether the failure error information is expected. Fixes: nodejs#47080
1f6dfc4 to
52038c0
Compare
| exists. Use the `errorOnExist` option to change this behavior. | ||
| **Default:** `true`. | ||
| * `mode` {integer} modifiers for copy operation. **Default:** `0`. | ||
| See `mode` flag of [`fsPromises.copyFile()`][] |
There was a problem hiding this comment.
| See `mode` flag of [`fsPromises.copyFile()`][] | |
| See `mode` flag of [`fsPromises.copyFile()`][]. |
| exists. Use the `errorOnExist` option to change this behavior. | ||
| **Default:** `true`. | ||
| * `mode` {integer} modifiers for copy operation. **Default:** `0`. | ||
| See `mode` flag of [`fs.copyFile()`][] |
There was a problem hiding this comment.
| See `mode` flag of [`fs.copyFile()`][] | |
| See `mode` flag of [`fs.copyFile()`][]. |
| exists. Use the `errorOnExist` option to change this behavior. | ||
| **Default:** `true`. | ||
| * `mode` {integer} modifiers for copy operation. **Default:** `0`. | ||
| See `mode` flag of [`fs.copyFileSync()`][] |
There was a problem hiding this comment.
| See `mode` flag of [`fs.copyFileSync()`][] | |
| See `mode` flag of [`fs.copyFileSync()`][]. |
|
|
||
| // It copies a nested folder structure with mode flags. | ||
| // This test is based on fs.promises.copyFile() with `COPYFILE_FICLONE_FORCE`. | ||
| await (async () => { |
There was a problem hiding this comment.
| await (async () => { | |
| { |
| // it should reach to here. | ||
| assert.strictEqual(p, undefined); | ||
| assertDirEquivalent(src, dest); | ||
| })(); |
4e1e069 to
6a2b4bc
Compare
|
@aduh95 Thank you for your review! |
fs.copyFile()supports copy-on-write operation if the underlying platform supports it by passing a mode flag. This behavior was added in a16d88d.This patch adds
modeflag tofs.cp(),fs.cpSync(), andfsPromises.cp()to allow to change their behaviors to copy files. This test case is based on the test case that was introduced when we addfs.constants.COPYFILE_FICLONE.a16d88d.
This test strategy is:
Fixes: #47080