Skip to content

Commit 0bc36ff

Browse files
manidlouRyanZim
authored andcommitted
v8 release (#667)
* Remove secure-random from dev-deps (#610) * fix ensureDir() doc * moveSync: refactor to use renameSync * copy*(): fix copying bind-mounted directories (#618) * copy*(): fix copying bind-mounted dirs * copy*(): fix case-insensitive-paths tests * copy*(): refactor to check paths more efficiently * destructure stats object after checking err * move*(): check paths before moving * move*(): add case-insensitive paths test * remove unnecessary done callback from test * copy*(): add new option checkPathsBeforeCopying * update copy*() docs to include checkPathsBeforeCopying * some reformatting * copy*(): use fs.stat with bigint option * move*(): refactor to use the internal stat functions * move*(): add test for prevent moving identical * disable graceful-fs in copy and move tests * fix parsing node version * tiny reformat * update copy*() docs * refactor parsing node version * use semver to parse node version in tests
1 parent 8e08791 commit 0bc36ff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1862
-634
lines changed

docs/copy-sync.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# copySync(src, dest, [options])
1+
# copySync(src, dest[, options])
22

33
Copy a file or directory. The directory can have contents. Like `cp -r`.
44

docs/copy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# copy(src, dest, [options, callback])
1+
# copy(src, dest[, options][, callback])
22

33
Copy a file or directory. The directory can have contents. Like `cp -r`.
44

docs/emptyDir.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# emptyDir(dir, [callback])
1+
# emptyDir(dir[, callback])
22

33
Ensures that a directory is empty. Deletes directory contents if the directory is not empty. If the directory does not exist, it is created. The directory itself is not deleted.
44

docs/ensureFile.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ensureFile(file, [callback])
1+
# ensureFile(file[, callback])
22

33
Ensures that the file exists. If the file that is requested to be created is in directories that do not exist, these directories are created. If the file already exists, it is **NOT MODIFIED**.
44

docs/ensureLink.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ensureLink(srcpath, dstpath, [callback])
1+
# ensureLink(srcpath, dstpath[, callback])
22

33
Ensures that the link exists. If the directory structure does not exist, it is created.
44

docs/ensureSymlink-sync.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ensureSymlinkSync(srcpath, dstpath, [type])
1+
# ensureSymlinkSync(srcpath, dstpath[, type])
22

33
Ensures that the symlink exists. If the directory structure does not exist, it is created.
44

docs/ensureSymlink.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ensureSymlink(srcpath, dstpath, [type, callback])
1+
# ensureSymlink(srcpath, dstpath[, type][, callback])
22

33
Ensures that the symlink exists. If the directory structure does not exist, it is created.
44

docs/move-sync.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# moveSync(src, dest, [options])
1+
# moveSync(src, dest[, options])
22

33
Moves a file or directory, even across devices.
44

docs/move.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# move(src, dest, [options, callback])
1+
# move(src, dest[, options][, callback])
22

33
Moves a file or directory, even across devices.
44

docs/outputFile-sync.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# outputFileSync(file, data, [options])
1+
# outputFileSync(file, data[, options])
22

33
Almost the same as `writeFileSync` (i.e. it [overwrites](http://pages.citebite.com/v2o5n8l2f5reb)), except that if the parent directory does not exist, it's created. `file` must be a file path (a buffer or a file descriptor is not allowed). `options` are what you'd pass to [`fs.writeFileSync()`](https://nodejs.org/api/fs.html#fs_fs_writefilesync_file_data_options).
44

docs/outputFile.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# outputFile(file, data, [options, callback])
1+
# outputFile(file, data[, options][, callback])
22

33
Almost the same as `writeFile` (i.e. it [overwrites](http://pages.citebite.com/v2o5n8l2f5reb)), except that if the parent directory does not exist, it's created. `file` must be a file path (a buffer or a file descriptor is not allowed). `options` are what you'd pass to [`fs.writeFile()`](https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback).
44

docs/outputJson-sync.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# outputJsonSync(file, object, [options])
1+
# outputJsonSync(file, object[, options])
22

33
Almost the same as [`writeJsonSync`](writeJson-sync.md), except that if the directory does not exist, it's created.
44

docs/outputJson.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# outputJson(file, object, [options, callback])
1+
# outputJson(file, object[, options][, callback])
22

33
Almost the same as [`writeJson`](writeJson.md), except that if the directory does not exist, it's created.
44

docs/readJson-sync.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# readJsonSync(file, [options])
1+
# readJsonSync(file[, options])
22

33
Reads a JSON file and then parses it into an object. `options` are the same
44
that you'd pass to [`jsonFile.readFileSync`](https://github.com/jprichardson/node-jsonfile#readfilesyncfilename-options).

docs/readJson.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# readJson(file, [options, callback])
1+
# readJson(file[, options][, callback])
22

33
Reads a JSON file and then parses it into an object. `options` are the same
44
that you'd pass to [`jsonFile.readFile`](https://github.com/jprichardson/node-jsonfile#readfilefilename-options-callback).

docs/remove.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# remove(path, [callback])
1+
# remove(path[, callback])
22

33
Removes a file or directory. The directory can have contents. Like `rm -rf`.
44

docs/writeJson-sync.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# writeJsonSync(file, object, [options])
1+
# writeJsonSync(file, object[, options])
22

33
Writes an object to a JSON file.
44

docs/writeJson.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# writeJson(file, object, [options, callback])
1+
# writeJson(file, object[, options][, callback])
22

33
Writes an object to a JSON file.
44

lib/copy-sync/__tests__/broken-symlink.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const fs = require('fs')
44
const os = require('os')
5-
const fse = require(process.cwd())
5+
const fse = require('../../')
66
const path = require('path')
77
const assert = require('assert')
88
const copySync = require('../copy-sync')

lib/copy-sync/__tests__/copy-sync-case-insensitive-paths.test.js

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
const assert = require('assert')
44
const os = require('os')
55
const path = require('path')
6-
const fs = require(process.cwd())
6+
const fs = require('../../')
7+
const platform = os.platform()
78

89
/* global beforeEach, afterEach, describe, it */
910

@@ -17,7 +18,7 @@ describe('+ copySync() - case insensitive paths', () => {
1718
fs.emptyDir(TEST_DIR, done)
1819
})
1920

20-
afterEach(done => fs.remove(TEST_DIR, done))
21+
afterEach(() => fs.removeSync(TEST_DIR))
2122

2223
describe('> when src is a directory', () => {
2324
it('should behave correctly based on the OS', () => {
@@ -29,15 +30,13 @@ describe('+ copySync() - case insensitive paths', () => {
2930
try {
3031
fs.copySync(src, dest)
3132
} catch (err) {
32-
if (os === 'darwin' || os === 'win32') {
33+
if (platform === 'darwin' || platform === 'win32') {
3334
assert.strictEqual(err.message, 'Source and destination must not be the same.')
34-
assert(fs.existsSync(src))
35-
assert(!fs.existsSync(dest))
3635
errThrown = true
3736
}
3837
}
39-
if (os === 'darwin' || os === 'win32') assert(errThrown)
40-
if (os === 'linux') {
38+
if (platform === 'darwin' || platform === 'win32') assert(errThrown)
39+
if (platform === 'linux') {
4140
assert(fs.existsSync(dest))
4241
assert.strictEqual(fs.readFileSync(path.join(dest, 'subdir', 'file.txt'), 'utf8'), 'some data')
4342
assert(!errThrown)
@@ -55,15 +54,13 @@ describe('+ copySync() - case insensitive paths', () => {
5554
try {
5655
fs.copySync(src, dest)
5756
} catch (err) {
58-
if (os === 'darwin' || os === 'win32') {
57+
if (platform === 'darwin' || platform === 'win32') {
5958
assert.strictEqual(err.message, 'Source and destination must not be the same.')
60-
assert(fs.existsSync(src))
61-
assert(!fs.existsSync(dest))
6259
errThrown = true
6360
}
6461
}
65-
if (os === 'darwin' || os === 'win32') assert(errThrown)
66-
if (os === 'linux') {
62+
if (platform === 'darwin' || platform === 'win32') assert(errThrown)
63+
if (platform === 'linux') {
6764
assert(fs.existsSync(dest))
6865
assert.strictEqual(fs.readFileSync(dest, 'utf8'), 'some data')
6966
assert(!errThrown)
@@ -77,25 +74,23 @@ describe('+ copySync() - case insensitive paths', () => {
7774
fs.outputFileSync(path.join(src, 'subdir', 'file.txt'), 'some data')
7875
const srcLink = path.join(TEST_DIR, 'src-symlink')
7976
fs.symlinkSync(src, srcLink, 'dir')
80-
dest = path.join(TEST_DIR, 'srcDir')
77+
dest = path.join(TEST_DIR, 'src-Symlink')
8178
let errThrown = false
8279

8380
try {
84-
fs.copySync(src, dest)
81+
fs.copySync(srcLink, dest)
8582
} catch (err) {
86-
if (os === 'darwin' || os === 'win32') {
83+
if (platform === 'darwin' || platform === 'win32') {
8784
assert.strictEqual(err.message, 'Source and destination must not be the same.')
88-
assert(fs.existsSync(src))
89-
assert(!fs.existsSync(dest))
9085
errThrown = true
9186
}
9287
}
93-
if (os === 'darwin' || os === 'win32') assert(errThrown)
94-
if (os === 'linux') {
88+
if (platform === 'darwin' || platform === 'win32') assert(errThrown)
89+
if (platform === 'linux') {
9590
assert(fs.existsSync(dest))
9691
assert.strictEqual(fs.readFileSync(path.join(dest, 'subdir', 'file.txt'), 'utf8'), 'some data')
97-
const link = fs.readlinkSync(srcLink)
98-
assert.strictEqual(link, dest)
92+
const destLink = fs.readlinkSync(dest)
93+
assert.strictEqual(destLink, src)
9994
assert(!errThrown)
10095
}
10196
})
@@ -105,25 +100,23 @@ describe('+ copySync() - case insensitive paths', () => {
105100
fs.outputFileSync(src, 'some data')
106101
const srcLink = path.join(TEST_DIR, 'src-symlink')
107102
fs.symlinkSync(src, srcLink, 'file')
108-
dest = path.join(TEST_DIR, 'srcFile')
103+
dest = path.join(TEST_DIR, 'src-Symlink')
109104
let errThrown = false
110105

111106
try {
112-
fs.copySync(src, dest)
107+
fs.copySync(srcLink, dest)
113108
} catch (err) {
114-
if (os === 'darwin' || os === 'win32') {
109+
if (platform === 'darwin' || platform === 'win32') {
115110
assert.strictEqual(err.message, 'Source and destination must not be the same.')
116-
assert(fs.existsSync(src))
117-
assert(!fs.existsSync(dest))
118111
errThrown = true
119112
}
120113
}
121-
if (os === 'darwin' || os === 'win32') assert(errThrown)
122-
if (os === 'linux') {
114+
if (platform === 'darwin' || platform === 'win32') assert(errThrown)
115+
if (platform === 'linux') {
123116
assert(fs.existsSync(dest))
124117
assert.strictEqual(fs.readFileSync(dest, 'utf8'), 'some data')
125-
const link = fs.readlinkSync(srcLink)
126-
assert.strictEqual(link, dest)
118+
const destLink = fs.readlinkSync(dest)
119+
assert.strictEqual(destLink, src)
127120
assert(!errThrown)
128121
}
129122
})

lib/copy-sync/__tests__/copy-sync-dir.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const fs = require(process.cwd())
3+
const fs = require('../../')
44
const os = require('os')
55
const path = require('path')
66
const assert = require('assert')
@@ -75,7 +75,7 @@ describe('+ copySync() / dir', () => {
7575
const srcTarget = path.join(TEST_DIR, 'destination')
7676
fs.mkdirSync(src)
7777
fs.mkdirSync(srcTarget)
78-
fs.symlinkSync(srcTarget, path.join(src, 'symlink'))
78+
fs.symlinkSync(srcTarget, path.join(src, 'symlink'), 'dir')
7979

8080
fs.copySync(src, dest)
8181

lib/copy-sync/__tests__/copy-sync-file.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const fs = require(process.cwd())
3+
const fs = require('../../')
44
const os = require('os')
55
const path = require('path')
66
const assert = require('assert')

lib/copy-sync/__tests__/copy-sync-preserve-time.test.js renamed to lib/copy-sync/__tests__/copy-sync-preserve-timestamp.test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
'use strict'
22

3-
const fs = require(process.cwd())
3+
const fs = require('../../')
44
const os = require('os')
55
const path = require('path')
66
const utimes = require('../../util/utimes')
77
const assert = require('assert')
8-
const nodeVersion = process.versions.node
9-
const nodeVersionMajor = parseInt(nodeVersion.split('.')[0], 10)
8+
const semver = require('semver')
9+
const nodeVersion = process.version
10+
const nodeVersionMajor = semver.major(nodeVersion)
1011

1112
/* global beforeEach, afterEach, describe, it */
1213

lib/copy-sync/__tests__/copy-sync-prevent-copying-identical.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const assert = require('assert')
44
const os = require('os')
55
const path = require('path')
6-
const fs = require(process.cwd())
6+
const fs = require('../../')
77
const klawSync = require('klaw-sync')
88

99
/* global beforeEach, afterEach, describe, it */

lib/copy-sync/__tests__/copy-sync-prevent-copying-into-itself.test.js

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const assert = require('assert')
44
const os = require('os')
55
const path = require('path')
6-
const fs = require(process.cwd())
6+
const fs = require('../../')
77
const klawSync = require('klaw-sync')
88

99
/* global beforeEach, afterEach, describe, it */
@@ -166,6 +166,56 @@ describe('+ copySync() - prevent copying into itself', () => {
166166
assert.strictEqual(link, src)
167167
})
168168

169+
it('should error when dest is a subdirectory of src (bind-mounted directory with subdirectory)', () => {
170+
const destLink = path.join(TEST_DIR, 'dest-symlink')
171+
fs.symlinkSync(src, destLink, 'dir')
172+
173+
const srclenBefore = klawSync(src).length
174+
assert(srclenBefore > 2)
175+
176+
const dest = path.join(destLink, 'dir1')
177+
assert(fs.existsSync(dest))
178+
let errThrown = false
179+
try {
180+
fs.copySync(src, dest)
181+
} catch (err) {
182+
assert.strictEqual(err.message, `Cannot copy '${src}' to a subdirectory of itself, '${dest}'.`)
183+
errThrown = true
184+
} finally {
185+
assert(errThrown)
186+
const srclenAfter = klawSync(src).length
187+
assert.strictEqual(srclenAfter, srclenBefore, 'src length should not change')
188+
189+
const link = fs.readlinkSync(destLink)
190+
assert.strictEqual(link, src)
191+
}
192+
})
193+
194+
it('should error when dest is a subdirectory of src (more than one level depth)', () => {
195+
const destLink = path.join(TEST_DIR, 'dest-symlink')
196+
fs.symlinkSync(src, destLink, 'dir')
197+
198+
const srclenBefore = klawSync(src).length
199+
assert(srclenBefore > 2)
200+
201+
const dest = path.join(destLink, 'dir1', 'dir2')
202+
assert(fs.existsSync(dest))
203+
let errThrown = false
204+
try {
205+
fs.copySync(src, dest)
206+
} catch (err) {
207+
assert.strictEqual(err.message, `Cannot copy '${src}' to a subdirectory of itself, '${path.join(destLink, 'dir1')}'.`)
208+
errThrown = true
209+
} finally {
210+
assert(errThrown)
211+
const srclenAfter = klawSync(src).length
212+
assert.strictEqual(srclenAfter, srclenBefore, 'src length should not change')
213+
214+
const link = fs.readlinkSync(destLink)
215+
assert.strictEqual(link, src)
216+
}
217+
})
218+
169219
it('should copy the directory successfully when src is a subdir of resolved dest path', () => {
170220
const srcInDest = path.join(TEST_DIR, 'dest', 'some', 'nested', 'src')
171221
const destLink = path.join(TEST_DIR, 'dest-symlink')
@@ -351,10 +401,6 @@ function testSuccess (src, dest) {
351401

352402
fs.copySync(src, dest)
353403

354-
const destlen = klawSync(dest).length
355-
356-
assert.strictEqual(destlen, srclen)
357-
358404
FILES.forEach(f => assert(fs.existsSync(path.join(dest, f)), 'file copied'))
359405

360406
const o0 = fs.readFileSync(path.join(dest, FILES[0]), 'utf8')

0 commit comments

Comments
 (0)