Skip to content

Commit

Permalink
v8 release (#667)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
manidlou authored and RyanZim committed May 11, 2019
1 parent 8e08791 commit 0bc36ff
Show file tree
Hide file tree
Showing 51 changed files with 1,862 additions and 634 deletions.
2 changes: 1 addition & 1 deletion docs/copy-sync.md
@@ -1,4 +1,4 @@
# copySync(src, dest, [options])
# copySync(src, dest[, options])

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

Expand Down
2 changes: 1 addition & 1 deletion docs/copy.md
@@ -1,4 +1,4 @@
# copy(src, dest, [options, callback])
# copy(src, dest[, options][, callback])

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

Expand Down
2 changes: 1 addition & 1 deletion docs/emptyDir.md
@@ -1,4 +1,4 @@
# emptyDir(dir, [callback])
# emptyDir(dir[, callback])

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.

Expand Down
2 changes: 1 addition & 1 deletion docs/ensureFile.md
@@ -1,4 +1,4 @@
# ensureFile(file, [callback])
# ensureFile(file[, callback])

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**.

Expand Down
2 changes: 1 addition & 1 deletion docs/ensureLink.md
@@ -1,4 +1,4 @@
# ensureLink(srcpath, dstpath, [callback])
# ensureLink(srcpath, dstpath[, callback])

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

Expand Down
2 changes: 1 addition & 1 deletion docs/ensureSymlink-sync.md
@@ -1,4 +1,4 @@
# ensureSymlinkSync(srcpath, dstpath, [type])
# ensureSymlinkSync(srcpath, dstpath[, type])

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

Expand Down
2 changes: 1 addition & 1 deletion docs/ensureSymlink.md
@@ -1,4 +1,4 @@
# ensureSymlink(srcpath, dstpath, [type, callback])
# ensureSymlink(srcpath, dstpath[, type][, callback])

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

Expand Down
2 changes: 1 addition & 1 deletion docs/move-sync.md
@@ -1,4 +1,4 @@
# moveSync(src, dest, [options])
# moveSync(src, dest[, options])

Moves a file or directory, even across devices.

Expand Down
2 changes: 1 addition & 1 deletion docs/move.md
@@ -1,4 +1,4 @@
# move(src, dest, [options, callback])
# move(src, dest[, options][, callback])

Moves a file or directory, even across devices.

Expand Down
2 changes: 1 addition & 1 deletion docs/outputFile-sync.md
@@ -1,4 +1,4 @@
# outputFileSync(file, data, [options])
# outputFileSync(file, data[, options])

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).

Expand Down
2 changes: 1 addition & 1 deletion docs/outputFile.md
@@ -1,4 +1,4 @@
# outputFile(file, data, [options, callback])
# outputFile(file, data[, options][, callback])

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).

Expand Down
2 changes: 1 addition & 1 deletion docs/outputJson-sync.md
@@ -1,4 +1,4 @@
# outputJsonSync(file, object, [options])
# outputJsonSync(file, object[, options])

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

Expand Down
2 changes: 1 addition & 1 deletion docs/outputJson.md
@@ -1,4 +1,4 @@
# outputJson(file, object, [options, callback])
# outputJson(file, object[, options][, callback])

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

Expand Down
2 changes: 1 addition & 1 deletion docs/readJson-sync.md
@@ -1,4 +1,4 @@
# readJsonSync(file, [options])
# readJsonSync(file[, options])

Reads a JSON file and then parses it into an object. `options` are the same
that you'd pass to [`jsonFile.readFileSync`](https://github.com/jprichardson/node-jsonfile#readfilesyncfilename-options).
Expand Down
2 changes: 1 addition & 1 deletion docs/readJson.md
@@ -1,4 +1,4 @@
# readJson(file, [options, callback])
# readJson(file[, options][, callback])

Reads a JSON file and then parses it into an object. `options` are the same
that you'd pass to [`jsonFile.readFile`](https://github.com/jprichardson/node-jsonfile#readfilefilename-options-callback).
Expand Down
2 changes: 1 addition & 1 deletion docs/remove.md
@@ -1,4 +1,4 @@
# remove(path, [callback])
# remove(path[, callback])

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

Expand Down
2 changes: 1 addition & 1 deletion docs/writeJson-sync.md
@@ -1,4 +1,4 @@
# writeJsonSync(file, object, [options])
# writeJsonSync(file, object[, options])

Writes an object to a JSON file.

Expand Down
2 changes: 1 addition & 1 deletion docs/writeJson.md
@@ -1,4 +1,4 @@
# writeJson(file, object, [options, callback])
# writeJson(file, object[, options][, callback])

Writes an object to a JSON file.

Expand Down
2 changes: 1 addition & 1 deletion lib/copy-sync/__tests__/broken-symlink.test.js
Expand Up @@ -2,7 +2,7 @@

const fs = require('fs')
const os = require('os')
const fse = require(process.cwd())
const fse = require('../../')
const path = require('path')
const assert = require('assert')
const copySync = require('../copy-sync')
Expand Down
53 changes: 23 additions & 30 deletions lib/copy-sync/__tests__/copy-sync-case-insensitive-paths.test.js
Expand Up @@ -3,7 +3,8 @@
const assert = require('assert')
const os = require('os')
const path = require('path')
const fs = require(process.cwd())
const fs = require('../../')
const platform = os.platform()

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

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

afterEach(done => fs.remove(TEST_DIR, done))
afterEach(() => fs.removeSync(TEST_DIR))

describe('> when src is a directory', () => {
it('should behave correctly based on the OS', () => {
Expand All @@ -29,15 +30,13 @@ describe('+ copySync() - case insensitive paths', () => {
try {
fs.copySync(src, dest)
} catch (err) {
if (os === 'darwin' || os === 'win32') {
if (platform === 'darwin' || platform === 'win32') {
assert.strictEqual(err.message, 'Source and destination must not be the same.')
assert(fs.existsSync(src))
assert(!fs.existsSync(dest))
errThrown = true
}
}
if (os === 'darwin' || os === 'win32') assert(errThrown)
if (os === 'linux') {
if (platform === 'darwin' || platform === 'win32') assert(errThrown)
if (platform === 'linux') {
assert(fs.existsSync(dest))
assert.strictEqual(fs.readFileSync(path.join(dest, 'subdir', 'file.txt'), 'utf8'), 'some data')
assert(!errThrown)
Expand All @@ -55,15 +54,13 @@ describe('+ copySync() - case insensitive paths', () => {
try {
fs.copySync(src, dest)
} catch (err) {
if (os === 'darwin' || os === 'win32') {
if (platform === 'darwin' || platform === 'win32') {
assert.strictEqual(err.message, 'Source and destination must not be the same.')
assert(fs.existsSync(src))
assert(!fs.existsSync(dest))
errThrown = true
}
}
if (os === 'darwin' || os === 'win32') assert(errThrown)
if (os === 'linux') {
if (platform === 'darwin' || platform === 'win32') assert(errThrown)
if (platform === 'linux') {
assert(fs.existsSync(dest))
assert.strictEqual(fs.readFileSync(dest, 'utf8'), 'some data')
assert(!errThrown)
Expand All @@ -77,25 +74,23 @@ describe('+ copySync() - case insensitive paths', () => {
fs.outputFileSync(path.join(src, 'subdir', 'file.txt'), 'some data')
const srcLink = path.join(TEST_DIR, 'src-symlink')
fs.symlinkSync(src, srcLink, 'dir')
dest = path.join(TEST_DIR, 'srcDir')
dest = path.join(TEST_DIR, 'src-Symlink')
let errThrown = false

try {
fs.copySync(src, dest)
fs.copySync(srcLink, dest)
} catch (err) {
if (os === 'darwin' || os === 'win32') {
if (platform === 'darwin' || platform === 'win32') {
assert.strictEqual(err.message, 'Source and destination must not be the same.')
assert(fs.existsSync(src))
assert(!fs.existsSync(dest))
errThrown = true
}
}
if (os === 'darwin' || os === 'win32') assert(errThrown)
if (os === 'linux') {
if (platform === 'darwin' || platform === 'win32') assert(errThrown)
if (platform === 'linux') {
assert(fs.existsSync(dest))
assert.strictEqual(fs.readFileSync(path.join(dest, 'subdir', 'file.txt'), 'utf8'), 'some data')
const link = fs.readlinkSync(srcLink)
assert.strictEqual(link, dest)
const destLink = fs.readlinkSync(dest)
assert.strictEqual(destLink, src)
assert(!errThrown)
}
})
Expand All @@ -105,25 +100,23 @@ describe('+ copySync() - case insensitive paths', () => {
fs.outputFileSync(src, 'some data')
const srcLink = path.join(TEST_DIR, 'src-symlink')
fs.symlinkSync(src, srcLink, 'file')
dest = path.join(TEST_DIR, 'srcFile')
dest = path.join(TEST_DIR, 'src-Symlink')
let errThrown = false

try {
fs.copySync(src, dest)
fs.copySync(srcLink, dest)
} catch (err) {
if (os === 'darwin' || os === 'win32') {
if (platform === 'darwin' || platform === 'win32') {
assert.strictEqual(err.message, 'Source and destination must not be the same.')
assert(fs.existsSync(src))
assert(!fs.existsSync(dest))
errThrown = true
}
}
if (os === 'darwin' || os === 'win32') assert(errThrown)
if (os === 'linux') {
if (platform === 'darwin' || platform === 'win32') assert(errThrown)
if (platform === 'linux') {
assert(fs.existsSync(dest))
assert.strictEqual(fs.readFileSync(dest, 'utf8'), 'some data')
const link = fs.readlinkSync(srcLink)
assert.strictEqual(link, dest)
const destLink = fs.readlinkSync(dest)
assert.strictEqual(destLink, src)
assert(!errThrown)
}
})
Expand Down
4 changes: 2 additions & 2 deletions lib/copy-sync/__tests__/copy-sync-dir.test.js
@@ -1,6 +1,6 @@
'use strict'

const fs = require(process.cwd())
const fs = require('../../')
const os = require('os')
const path = require('path')
const assert = require('assert')
Expand Down Expand Up @@ -75,7 +75,7 @@ describe('+ copySync() / dir', () => {
const srcTarget = path.join(TEST_DIR, 'destination')
fs.mkdirSync(src)
fs.mkdirSync(srcTarget)
fs.symlinkSync(srcTarget, path.join(src, 'symlink'))
fs.symlinkSync(srcTarget, path.join(src, 'symlink'), 'dir')

fs.copySync(src, dest)

Expand Down
2 changes: 1 addition & 1 deletion lib/copy-sync/__tests__/copy-sync-file.test.js
@@ -1,6 +1,6 @@
'use strict'

const fs = require(process.cwd())
const fs = require('../../')
const os = require('os')
const path = require('path')
const assert = require('assert')
Expand Down
@@ -1,12 +1,13 @@
'use strict'

const fs = require(process.cwd())
const fs = require('../../')
const os = require('os')
const path = require('path')
const utimes = require('../../util/utimes')
const assert = require('assert')
const nodeVersion = process.versions.node
const nodeVersionMajor = parseInt(nodeVersion.split('.')[0], 10)
const semver = require('semver')
const nodeVersion = process.version
const nodeVersionMajor = semver.major(nodeVersion)

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

Expand Down
Expand Up @@ -3,7 +3,7 @@
const assert = require('assert')
const os = require('os')
const path = require('path')
const fs = require(process.cwd())
const fs = require('../../')
const klawSync = require('klaw-sync')

/* global beforeEach, afterEach, describe, it */
Expand Down
Expand Up @@ -3,7 +3,7 @@
const assert = require('assert')
const os = require('os')
const path = require('path')
const fs = require(process.cwd())
const fs = require('../../')
const klawSync = require('klaw-sync')

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

it('should error when dest is a subdirectory of src (bind-mounted directory with subdirectory)', () => {
const destLink = path.join(TEST_DIR, 'dest-symlink')
fs.symlinkSync(src, destLink, 'dir')

const srclenBefore = klawSync(src).length
assert(srclenBefore > 2)

const dest = path.join(destLink, 'dir1')
assert(fs.existsSync(dest))
let errThrown = false
try {
fs.copySync(src, dest)
} catch (err) {
assert.strictEqual(err.message, `Cannot copy '${src}' to a subdirectory of itself, '${dest}'.`)
errThrown = true
} finally {
assert(errThrown)
const srclenAfter = klawSync(src).length
assert.strictEqual(srclenAfter, srclenBefore, 'src length should not change')

const link = fs.readlinkSync(destLink)
assert.strictEqual(link, src)
}
})

it('should error when dest is a subdirectory of src (more than one level depth)', () => {
const destLink = path.join(TEST_DIR, 'dest-symlink')
fs.symlinkSync(src, destLink, 'dir')

const srclenBefore = klawSync(src).length
assert(srclenBefore > 2)

const dest = path.join(destLink, 'dir1', 'dir2')
assert(fs.existsSync(dest))
let errThrown = false
try {
fs.copySync(src, dest)
} catch (err) {
assert.strictEqual(err.message, `Cannot copy '${src}' to a subdirectory of itself, '${path.join(destLink, 'dir1')}'.`)
errThrown = true
} finally {
assert(errThrown)
const srclenAfter = klawSync(src).length
assert.strictEqual(srclenAfter, srclenBefore, 'src length should not change')

const link = fs.readlinkSync(destLink)
assert.strictEqual(link, src)
}
})

it('should copy the directory successfully when src is a subdir of resolved dest path', () => {
const srcInDest = path.join(TEST_DIR, 'dest', 'some', 'nested', 'src')
const destLink = path.join(TEST_DIR, 'dest-symlink')
Expand Down Expand Up @@ -351,10 +401,6 @@ function testSuccess (src, dest) {

fs.copySync(src, dest)

const destlen = klawSync(dest).length

assert.strictEqual(destlen, srclen)

FILES.forEach(f => assert(fs.existsSync(path.join(dest, f)), 'file copied'))

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

0 comments on commit 0bc36ff

Please sign in to comment.