From 3451bbed1135748aaa54643ab0c96679fc7518db Mon Sep 17 00:00:00 2001 From: Tetsuharu Ohzeki Date: Thu, 16 Mar 2023 22:45:50 +0900 Subject: [PATCH] fixup! fs: `fs.cp()` should accept `mode` flag to specify the copy behavior --- test/parallel/test-fs-cp.mjs | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/test/parallel/test-fs-cp.mjs b/test/parallel/test-fs-cp.mjs index af1a021d3a24c7..a577d78bc50547 100644 --- a/test/parallel/test-fs-cp.mjs +++ b/test/parallel/test-fs-cp.mjs @@ -40,7 +40,7 @@ function nextdir() { // It copies a nested folder structure with mode flags. // This test is based on fs.promises.copyFile() with `COPYFILE_FICLONE_FORCE`. -{ +(() => { const src = './test/fixtures/copy/kitchen-sink'; const dest = nextdir(); try { @@ -48,17 +48,19 @@ function nextdir() { recursive: true, mode: fs.constants.COPYFILE_FICLONE_FORCE, })); - assertDirEquivalent(src, dest); - // If the platform support `COPYFILE_FICLONE_FORCE` operation, - // it should reach to here. } 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. + assertDirEquivalent(src, dest); +})(); // It does not throw errors when directory is copied over and force is false. { @@ -875,26 +877,29 @@ 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; try { - const p = await fs.promises.cp(src, dest, mustNotMutateObjectDeep({ + p = await fs.promises.cp(src, dest, mustNotMutateObjectDeep({ recursive: true, mode: fs.constants.COPYFILE_FICLONE_FORCE, })); - assert.strictEqual(p, undefined); - assertDirEquivalent(src, dest); - // If the platform support `COPYFILE_FICLONE_FORCE` operation, - // it should reach to here. } 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); +})(); // It accepts file URL as src and dest. {