Skip to content

fs: fs.cp() should accept mode flag to specify the copy behavior#47084

Merged
nodejs-github-bot merged 2 commits into
nodejs:mainfrom
tetsuharuohzeki:allow-to-pass-mode-flag-for-cp
Apr 20, 2023
Merged

fs: fs.cp() should accept mode flag to specify the copy behavior#47084
nodejs-github-bot merged 2 commits into
nodejs:mainfrom
tetsuharuohzeki:allow-to-pass-mode-flag-for-cp

Conversation

@tetsuharuohzeki

Copy link
Copy Markdown
Contributor

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 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.
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: #47080

@nodejs-github-bot nodejs-github-bot added fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run. labels Mar 14, 2023
@debadree25

Copy link
Copy Markdown
Contributor

cc @nodejs/fs

@tetsuharuohzeki tetsuharuohzeki force-pushed the allow-to-pass-mode-flag-for-cp branch from 3579490 to 1b4e164 Compare March 14, 2023 07:38
assertDirEquivalent(src, dest);
// If the platform support `COPYFILE_FICLONE_FORCE` operation,
// it should reach to here.
} catch (err) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This catch block also catches assertDirEquivalent failures, doesn't it? Better to move that outside the block.

(Also applies to code further below.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This catch block also catches assertDirEquivalent failures, doesn't it?

Yes, it is. I addressed them in 3451bbe.

@tetsuharuohzeki

Copy link
Copy Markdown
Contributor Author

@bnoordhuis How about this? Could you review this again?

@tetsuharuohzeki

Copy link
Copy Markdown
Contributor Author

@nodejs/fs

Could you review this?

@bnoordhuis

Copy link
Copy Markdown
Member

@tetsuharuohzeki my comment was a drive-by thing, just something I noticed. I'll leave signing off on the main change to @nodejs/fs.

@tetsuharuohzeki tetsuharuohzeki force-pushed the allow-to-pass-mode-flag-for-cp branch from 3451bbe to 34dc434 Compare March 29, 2023 11:38
@tetsuharuohzeki

Copy link
Copy Markdown
Contributor Author

I rebased this on the latest main.

@aduh95

aduh95 commented Apr 14, 2023

Copy link
Copy Markdown
Contributor

Can you amend the commit message so it matches our commit message guidelines?

* be prefixed with the name of the changed [subsystem](#appendix-subsystems)
and start with an imperative verb. Check the output of `git log --oneline

E.g. fs: add support for mode flag to specify the copy behavior would work.

@aduh95 aduh95 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an entry in the YAML history section for each modified fs method?

node/doc/api/fs.md

Lines 5193 to 5199 in a9c3d92

changes:
- version:
- v17.6.0
- v16.15.0
pr-url: https://github.com/nodejs/node/pull/41819
description: Accepts an additional `verbatimSymlinks` option to specify
whether to perform path resolution for symlinks.

@aduh95 aduh95 added the semver-minor PRs that contain new features and should be released in the next minor version. label Apr 14, 2023
@tetsuharuohzeki tetsuharuohzeki force-pushed the allow-to-pass-mode-flag-for-cp branch from 34dc434 to fc8eafe Compare April 14, 2023 13:16
@tetsuharuohzeki

Copy link
Copy Markdown
Contributor Author

@aduh95

Thank you for your review! I addressed my patch.
How about this?

@debadree25 debadree25 added the review wanted PRs that need reviews. label Apr 14, 2023
@tetsuharuohzeki tetsuharuohzeki force-pushed the allow-to-pass-mode-flag-for-cp branch from fc8eafe to 1f6dfc4 Compare April 14, 2023 13:27
`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
@tetsuharuohzeki tetsuharuohzeki force-pushed the allow-to-pass-mode-flag-for-cp branch from 1f6dfc4 to 52038c0 Compare April 14, 2023 15:55
Comment thread doc/api/fs.md Outdated
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()`][]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
See `mode` flag of [`fsPromises.copyFile()`][]
See `mode` flag of [`fsPromises.copyFile()`][].

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 6a2b4bc

Comment thread doc/api/fs.md Outdated
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()`][]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
See `mode` flag of [`fs.copyFile()`][]
See `mode` flag of [`fs.copyFile()`][].

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 6a2b4bc

Comment thread doc/api/fs.md Outdated
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()`][]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
See `mode` flag of [`fs.copyFileSync()`][]
See `mode` flag of [`fs.copyFileSync()`][].

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 6a2b4bc

Comment thread test/parallel/test-fs-cp.mjs Outdated

// It copies a nested folder structure with mode flags.
// This test is based on fs.promises.copyFile() with `COPYFILE_FICLONE_FORCE`.
await (async () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await (async () => {
{

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 6a2b4bc

Comment thread test/parallel/test-fs-cp.mjs Outdated
// it should reach to here.
assert.strictEqual(p, undefined);
assertDirEquivalent(src, dest);
})();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
})();
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 6a2b4bc

@tetsuharuohzeki tetsuharuohzeki force-pushed the allow-to-pass-mode-flag-for-cp branch from 4e1e069 to 6a2b4bc Compare April 14, 2023 17:08
@tetsuharuohzeki tetsuharuohzeki requested a review from aduh95 April 14, 2023 17:09
@aduh95 aduh95 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Apr 14, 2023
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 14, 2023
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@tetsuharuohzeki

Copy link
Copy Markdown
Contributor Author

@aduh95 Thank you for your review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run. review wanted PRs that need reviews. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fs.cp() should support copy-on-write operation if the underlying platform supports it

5 participants