Skip to content

Commit cb349d1

Browse files
author
bcoe
committed
address code review fix tests
1 parent 83a403c commit cb349d1

File tree

5 files changed

+21
-20
lines changed

5 files changed

+21
-20
lines changed

doc/api/errors.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ added: REPLACEME
11271127
-->
11281128

11291129
An attempt was made to copy over a file that already existed with
1130-
[`fs.copy()`][], with the `overwrite` and `errorOnExist` set to `true`.
1130+
[`fs.copy()`][], with the `force` and `errorOnExist` set to `true`.
11311131

11321132
<a id="ERR_FS_COPY_FIFO_PIPE"></a>
11331133
### `ERR_FS_COPY_FIFO_PIPE`
@@ -1169,7 +1169,7 @@ of `src`.
11691169
added: REPLACEME
11701170
-->
11711171

1172-
When using [`fs.copy()`][], `dest` pointed to a subfolder in `src`.
1172+
When using [`fs.copy()`][], `dest` pointed to a subdirectory in `src`.
11731173

11741174
<a id="ERR_FS_COPY_UNKNOWN"></a>
11751175
### `ERR_FS_COPY_UNKNOWN`

doc/api/fs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4267,7 +4267,7 @@ through any other `fs` operation may lead to undefined behavior.
42674267
42684268
See the POSIX close(2) documentation for more detail.
42694269
4270-
### `fs.copy(src, dest[, options])`
4270+
### `fs.copySync(src, dest[, options])`
42714271
<!-- YAML
42724272
added: REPLACEME
42734273
-->

lib/internal/fs/copy/copy-sync.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@ const {
3333
const fs = require('fs');
3434
const {
3535
chmodSync,
36-
closeSync,
3736
copyFileSync,
3837
existsSync,
3938
lstatSync,
4039
mkdirSync,
41-
openSync,
4240
readdirSync,
4341
readlinkSync,
4442
statSync,
@@ -57,7 +55,7 @@ const {
5755
function copySyncFn(src, dest, opts) {
5856
// Warn about using preserveTimestamps on 32-bit node
5957
if (opts.preserveTimestamps && process.arch === 'ia32') {
60-
const warning = 'Using the preserveTimestamps option in 32-bit' +
58+
const warning = 'Using the preserveTimestamps option in 32-bit ' +
6159
'node is not recommended';
6260
process.emitWarning(warning, 'TimestampPrecisionWarning');
6361
}
@@ -73,7 +71,7 @@ function checkPathsSync(src, dest, opts) {
7371
if (areIdentical(srcStat, destStat)) {
7472
throw new ERR_FS_COPY_TO_SUBDIRECTORY({
7573
code: 'EINVAL',
76-
message: 'src and dest cannot be the same directory',
74+
message: 'src and dest cannot be the same',
7775
path: dest,
7876
syscall: 'copy',
7977
errno: EINVAL,

lib/internal/fs/copy/copy.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ const {
4646
copyFile,
4747
lstat,
4848
mkdir,
49-
open,
5049
readdir,
5150
readlink,
5251
stat,
@@ -66,7 +65,7 @@ const {
6665
async function copyFn(src, dest, opts) {
6766
// Warn about using preserveTimestamps on 32-bit node
6867
if (opts.preserveTimestamps && process.arch === 'ia32') {
69-
const warning = 'Using the preserveTimestamps option in 32-bit' +
68+
const warning = 'Using the preserveTimestamps option in 32-bit ' +
7069
'node is not recommended';
7170
process.emitWarning(warning, 'TimestampPrecisionWarning');
7271
}
@@ -86,7 +85,7 @@ async function checkPaths(src, dest, opts) {
8685
if (areIdentical(srcStat, destStat)) {
8786
throw new ERR_FS_COPY_TO_SUBDIRECTORY({
8887
code: 'EINVAL',
89-
message: 'src and dest cannot be the same directory',
88+
message: 'src and dest cannot be the same',
9089
path: dest,
9190
syscall: 'copy',
9291
errno: EINVAL,

test/parallel/test-fs-copy.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const {
1212
lstatSync,
1313
mkdirSync,
1414
readdirSync,
15+
readFileSync,
1516
symlinkSync,
1617
statSync,
1718
writeFileSync,
@@ -58,16 +59,13 @@ function nextdir() {
5859
{
5960
const src = dirname(require.resolve('../fixtures/copy/kitchen-sink'));
6061
const dest = nextdir();
61-
copySync(src, dest);
62-
const initialStat = lstatSync(join(dest, 'README.md'));
62+
mkdirSync(dest, { recursive: true });
63+
writeFileSync(join(dest, 'README.md'), '# Goodbye\n', 'utf8');
64+
6365
copy(src, dest, { force: true }, common.mustCall((err) => {
6466
assertDirEquivalent(src, dest);
65-
// File was copied over, so creation time will differ.
66-
const finalStat = lstatSync(join(dest, 'README.md'));
67-
assert.notStrictEqual(
68-
finalStat.ctime.getTime(),
69-
initialStat.ctime.getTime()
70-
);
67+
const content = readFileSync(join(dest, 'README.md'), 'utf8');
68+
assert.strictEqual(content, '# Hello\n');
7169
}));
7270
}
7371

@@ -120,7 +118,10 @@ function nextdir() {
120118

121119
// It returns error if symlink in dest points to location in src.
122120
{
123-
const src = dirname(require.resolve('../fixtures/copy/kitchen-sink'));
121+
const src = nextdir();
122+
mkdirSync(join(src, 'a', 'b'), { recursive: true });
123+
symlinkSync(join(src, 'a', 'b'), join(src, 'a', 'c'));
124+
124125
const dest = nextdir();
125126
mkdirSync(join(dest, 'a'), { recursive: true });
126127
symlinkSync(src, join(dest, 'a', 'c'));
@@ -248,7 +249,10 @@ if (!isWindows) {
248249

249250
// It returns EEXIST error if attempt is made to copy symlink over file.
250251
{
251-
const src = dirname(require.resolve('../fixtures/copy/kitchen-sink'));
252+
const src = nextdir();
253+
mkdirSync(join(src, 'a', 'b'), { recursive: true });
254+
symlinkSync(join(src, 'a', 'b'), join(src, 'a', 'c'));
255+
252256
const dest = nextdir();
253257
mkdirSync(join(dest, 'a'), { recursive: true });
254258
writeFileSync(join(dest, 'a', 'c'), 'hello', 'utf8');

0 commit comments

Comments
 (0)