Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ changes:
operation. It is possible to create a mask consisting of the bitwise OR of
two or more values (e.g.
`fs.constants.COPYFILE_EXCL | fs.constants.COPYFILE_FICLONE`)
**Default:** `0`.
**Default:** `fs.constants.COPYFILE_FICLONE`.
* `fs.constants.COPYFILE_EXCL`: The copy operation will fail if `dest`
already exists.
* `fs.constants.COPYFILE_FICLONE`: The copy operation will attempt to create
Expand Down Expand Up @@ -5187,7 +5187,7 @@ changes:

* `src` {string|Buffer|URL} source filename to copy
* `dest` {string|Buffer|URL} destination filename of the copy operation
* `mode` {integer} modifiers for copy operation. **Default:** `0`.
* `mode` {integer} modifiers for copy operation. **Default:** `fs.constants.COPYFILE_FICLONE`.

Synchronously copies `src` to `dest`. By default, `dest` is overwritten if it
already exists. Returns `undefined`. Node.js makes no guarantees about the
Expand Down
3 changes: 2 additions & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const {
} = require('internal/util');
const {
constants: {
kDefaultCopyMode,
kIoMaxLength,
kMaxUserId,
},
Expand Down Expand Up @@ -2942,7 +2943,7 @@ function mkdtempSync(prefix, options) {
function copyFile(src, dest, mode, callback) {
if (typeof mode === 'function') {
callback = mode;
mode = 0;
mode = kDefaultCopyMode;
}

src = getValidatedPath(src, 'src');
Expand Down
10 changes: 3 additions & 7 deletions lib/internal/fs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,11 @@ const {
const kMinimumAccessMode = MathMin(F_OK, W_OK, R_OK, X_OK);
const kMaximumAccessMode = F_OK | W_OK | R_OK | X_OK;

const kDefaultCopyMode = 0;
const kDefaultCopyMode = COPYFILE_FICLONE;
// The copy modes can be any of COPYFILE_EXCL, COPYFILE_FICLONE or
// COPYFILE_FICLONE_FORCE. They can be used in combination as well
// (COPYFILE_EXCL | COPYFILE_FICLONE | COPYFILE_FICLONE_FORCE).
const kMinimumCopyMode = MathMin(
kDefaultCopyMode,
COPYFILE_EXCL,
COPYFILE_FICLONE,
COPYFILE_FICLONE_FORCE,
);
const kMinimumCopyMode = 0;
const kMaximumCopyMode = COPYFILE_EXCL |
COPYFILE_FICLONE |
COPYFILE_FICLONE_FORCE;
Expand Down Expand Up @@ -927,6 +922,7 @@ const validatePosition = hideStackFrames((position, name) => {

module.exports = {
constants: {
kDefaultCopyMode,
kIoMaxLength,
kMaxUserId,
kReadFileBufferLength,
Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-fs-copyfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const fs = require('fs');
const { internalBinding } = require('internal/test/binding');
const { getValidMode } = require('internal/fs/utils');
const {
UV_ENOENT,
UV_EEXIST
Expand Down Expand Up @@ -61,6 +62,9 @@ fs.unlinkSync(dest);
fs.copyFileSync(src, dest, UV_FS_COPYFILE_FICLONE);
verify(src, dest);

// Verify that default mode is COPYFILE_FICLONE.
assert.strictEqual(getValidMode(null, 'copyFile'), COPYFILE_FICLONE);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I am not really sure how to test it.

Input is welcomed! 😄


// Verify that COPYFILE_FICLONE_FORCE can be used.
try {
fs.unlinkSync(dest);
Expand Down