Skip to content

Commit 843999c

Browse files
committed
fs: Change default mode to COPYFILE_FICLONE
1 parent 19afcba commit 843999c

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

doc/api/fs.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ changes:
924924
operation. It is possible to create a mask consisting of the bitwise OR of
925925
two or more values (e.g.
926926
`fs.constants.COPYFILE_EXCL | fs.constants.COPYFILE_FICLONE`)
927-
**Default:** `0`.
927+
**Default:** `fs.constants.COPYFILE_FICLONE`.
928928
* `fs.constants.COPYFILE_EXCL`: The copy operation will fail if `dest`
929929
already exists.
930930
* `fs.constants.COPYFILE_FICLONE`: The copy operation will attempt to create
@@ -5187,7 +5187,7 @@ changes:
51875187

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

51925192
Synchronously copies `src` to `dest`. By default, `dest` is overwritten if it
51935193
already exists. Returns `undefined`. Node.js makes no guarantees about the

lib/fs.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const {
9292
} = require('internal/util');
9393
const {
9494
constants: {
95+
kDefaultCopyMode,
9596
kIoMaxLength,
9697
kMaxUserId,
9798
},
@@ -2942,7 +2943,7 @@ function mkdtempSync(prefix, options) {
29422943
function copyFile(src, dest, mode, callback) {
29432944
if (typeof mode === 'function') {
29442945
callback = mode;
2945-
mode = 0;
2946+
mode = kDefaultCopyMode;
29462947
}
29472948

29482949
src = getValidatedPath(src, 'src');

lib/internal/fs/utils.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,11 @@ const {
112112
const kMinimumAccessMode = MathMin(F_OK, W_OK, R_OK, X_OK);
113113
const kMaximumAccessMode = F_OK | W_OK | R_OK | X_OK;
114114

115-
const kDefaultCopyMode = 0;
115+
const kDefaultCopyMode = COPYFILE_FICLONE;
116116
// The copy modes can be any of COPYFILE_EXCL, COPYFILE_FICLONE or
117117
// COPYFILE_FICLONE_FORCE. They can be used in combination as well
118118
// (COPYFILE_EXCL | COPYFILE_FICLONE | COPYFILE_FICLONE_FORCE).
119-
const kMinimumCopyMode = MathMin(
120-
kDefaultCopyMode,
121-
COPYFILE_EXCL,
122-
COPYFILE_FICLONE,
123-
COPYFILE_FICLONE_FORCE,
124-
);
119+
const kMinimumCopyMode = 0;
125120
const kMaximumCopyMode = COPYFILE_EXCL |
126121
COPYFILE_FICLONE |
127122
COPYFILE_FICLONE_FORCE;
@@ -927,6 +922,7 @@ const validatePosition = hideStackFrames((position, name) => {
927922

928923
module.exports = {
929924
constants: {
925+
kDefaultCopyMode,
930926
kIoMaxLength,
931927
kMaxUserId,
932928
kReadFileBufferLength,

test/parallel/test-fs-copyfile.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const tmpdir = require('../common/tmpdir');
66
const assert = require('assert');
77
const fs = require('fs');
88
const { internalBinding } = require('internal/test/binding');
9+
const { getValidMode } = require('internal/fs/utils');
910
const {
1011
UV_ENOENT,
1112
UV_EEXIST
@@ -61,6 +62,9 @@ fs.unlinkSync(dest);
6162
fs.copyFileSync(src, dest, UV_FS_COPYFILE_FICLONE);
6263
verify(src, dest);
6364

65+
// Verify that default mode is COPYFILE_FICLONE.
66+
assert.strictEqual(getValidMode(null, 'copyFile'), COPYFILE_FICLONE);
67+
6468
// Verify that COPYFILE_FICLONE_FORCE can be used.
6569
try {
6670
fs.unlinkSync(dest);

0 commit comments

Comments
 (0)