From 52038c0d9e4a326e6b69df2ebc1300a2fa179087 Mon Sep 17 00:00:00 2001 From: Tetsuharu Ohzeki Date: Tue, 14 Mar 2023 14:42:02 +0900 Subject: [PATCH 1/2] fs: add support for mode flag to specify the copy behavior `fs.copyFile()` supports copy-on-write operation if the underlying platform supports it by passing a mode flag. This behavior was added in https://github.com/nodejs/node/commit/a16d88d9e9a6581e463082549823189aba25ca76. 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`. https://github.com/nodejs/node/commit/a16d88d9e9a6581e463082549823189aba25ca76. 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: https://github.com/nodejs/node/issues/47080 --- doc/api/fs.md | 20 +++++++ lib/internal/fs/cp/cp-sync.js | 2 +- lib/internal/fs/cp/cp.js | 2 +- lib/internal/fs/utils.js | 1 + test/parallel/test-fs-cp.mjs | 101 ++++++++++++++++++++++++++++++++++ 5 files changed, 124 insertions(+), 2 deletions(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index 44bcd28a2ce638..a0fad8254b6580 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -966,6 +966,10 @@ try {