From 383a3f8b708c3093418e4ef341865c02585c012c Mon Sep 17 00:00:00 2001 From: Tetsuharu Ohzeki Date: Thu, 20 Apr 2023 15:28:18 +0900 Subject: [PATCH] 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 PR-URL: https://github.com/nodejs/node/pull/47084 Reviewed-By: Antoine du Hamel --- doc/api/fs.md | 22 ++++++- 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 | 104 ++++++++++++++++++++++++++++++++++ 5 files changed, 128 insertions(+), 3 deletions(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index c3b4fc54734728..8daaf8ee9685ca 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -962,6 +962,10 @@ try {