Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v8 release #667

Merged
merged 19 commits into from May 11, 2019
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 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 All @@ -7,6 +7,7 @@ Copy a file or directory. The directory can have contents. Like `cp -r`.
- `options` `<Object>`
- `overwrite` `<boolean>`: overwrite existing file or directory, default is `true`. _Note that the copy operation will silently fail if you set this to `false` and the destination exists._ Use the `errorOnExist` option to change this behavior.
- `errorOnExist` `<boolean>`: when `overwrite` is `false` and the destination exists, throw an error. Default is `false`.
- `checkPathsBeforeCopying` `<boolean>`: check `src` and `dest` paths before copying. Default is `true`.
- `dereference` `<boolean>`: dereference symlinks, default is `false`.
- `preserveTimestamps` `<boolean>`: When true, will set last modification and access times to the ones of the original source files. When false, timestamp behavior is OS-dependent. Default is `false`.
- `filter` `<Function>`: Function to filter copied files. Return `true` to include, `false` to exclude.
Expand Down
3 changes: 2 additions & 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 All @@ -7,6 +7,7 @@ Copy a file or directory. The directory can have contents. Like `cp -r`.
- `options` `<Object>`
- `overwrite` `<boolean>`: overwrite existing file or directory, default is `true`. _Note that the copy operation will silently fail if you set this to `false` and the destination exists._ Use the `errorOnExist` option to change this behavior.
- `errorOnExist` `<boolean>`: when `overwrite` is `false` and the destination exists, throw an error. Default is `false`.
- `checkPathsBeforeCopying` `<boolean>`: check `src` and `dest` paths before copying. Default is `true`.
- `dereference` `<boolean>`: dereference symlinks, default is `false`.
- `preserveTimestamps` `<boolean>`: When true, will set last modification and access times to the ones of the original source files. When false, timestamp behavior is OS-dependent. Default is `false`.
- `filter` `<Function>`: Function to filter copied files. Return `true` to include, `false` to exclude. Can also return a `Promise` that resolves to `true` or `false` (or pass in an `async` function).
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
2 changes: 1 addition & 1 deletion lib/copy-sync/__tests__/copy-sync-preserve-time.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 utimes = require('../../util/utimes')
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