From 6a2b4bc7a566568ca65d5bcfc255a5761e424289 Mon Sep 17 00:00:00 2001 From: Tetsuharu Ohzeki Date: Sat, 15 Apr 2023 01:17:05 +0900 Subject: [PATCH] fixup! fs: add support for mode flag to specify the copy behavior --- doc/api/fs.md | 6 +++--- test/parallel/test-fs-cp.mjs | 17 ++++++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index a0fad8254b6580..c3a4a857e86a29 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -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` @@ -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` @@ -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` diff --git a/test/parallel/test-fs-cp.mjs b/test/parallel/test-fs-cp.mjs index 9434f64cf1f40d..8aedad334d2b24 100644 --- a/test/parallel/test-fs-cp.mjs +++ b/test/parallel/test-fs-cp.mjs @@ -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. {