Skip to content

Commit

Permalink
fixup! fs: add support for mode flag to specify the copy behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
tetsuharuohzeki committed Apr 14, 2023
1 parent 52038c0 commit 6a2b4bc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ changes:
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()`][]
See `mode` flag of [`fsPromises.copyFile()`][].
* `preserveTimestamps` {boolean} When `true` timestamps from `src` will
be preserved. **Default:** `false`.
* `recursive` {boolean} copy directories recursively **Default:** `false`
Expand Down Expand Up @@ -2328,7 +2328,7 @@ changes:
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()`][]
See `mode` flag of [`fs.copyFile()`][].
* `preserveTimestamps` {boolean} When `true` timestamps from `src` will
be preserved. **Default:** `false`.
* `recursive` {boolean} copy directories recursively **Default:** `false`
Expand Down Expand Up @@ -5233,7 +5233,7 @@ changes:
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()`][]
See `mode` flag of [`fs.copyFileSync()`][].
* `preserveTimestamps` {boolean} When `true` timestamps from `src` will
be preserved. **Default:** `false`.
* `recursive` {boolean} copy directories recursively **Default:** `false`
Expand Down
17 changes: 10 additions & 7 deletions test/parallel/test-fs-cp.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -877,29 +877,32 @@ if (!isWindows) {

// It copies a nested folder structure with mode flags.
// This test is based on fs.promises.copyFile() with `COPYFILE_FICLONE_FORCE`.
await (async () => {
{
const src = './test/fixtures/copy/kitchen-sink';
const dest = nextdir();
let p = null;
let successFiClone = false;
try {
p = await fs.promises.cp(src, dest, mustNotMutateObjectDeep({
recursive: true,
mode: fs.constants.COPYFILE_FICLONE_FORCE,
}));
successFiClone = true;
} catch (err) {
// If the platform does not support `COPYFILE_FICLONE_FORCE` operation,
// it should enter this path.
assert.strictEqual(err.syscall, 'copyfile');
assert(err.code === 'ENOTSUP' || err.code === 'ENOTTY' ||
err.code === 'ENOSYS' || err.code === 'EXDEV');
return;
}

// If the platform support `COPYFILE_FICLONE_FORCE` operation,
// it should reach to here.
assert.strictEqual(p, undefined);
assertDirEquivalent(src, dest);
})();
if (successFiClone) {
// If the platform support `COPYFILE_FICLONE_FORCE` operation,
// it should reach to here.
assert.strictEqual(p, undefined);
assertDirEquivalent(src, dest);
}
}

// It accepts file URL as src and dest.
{
Expand Down

0 comments on commit 6a2b4bc

Please sign in to comment.