Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jprichardson/node-fs-extra
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 7.0.1
Choose a base ref
...
head repository: jprichardson/node-fs-extra
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8.0.0
Choose a head ref
  • 3 commits
  • 53 files changed
  • 3 contributors

Commits on Feb 19, 2019

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    8e08791 View commit details

Commits on May 11, 2019

  1. 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
    manidlou authored and RyanZim committed May 11, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    0bc36ff View commit details
  2. 8.0.0

    RyanZim committed May 11, 2019
    Copy the full SHA
    a7f303b View commit details
Showing with 1,874 additions and 636 deletions.
  1. +10 −0 CHANGELOG.md
  2. +1 −1 README.md
  3. +1 −1 docs/copy-sync.md
  4. +1 −1 docs/copy.md
  5. +1 −1 docs/emptyDir.md
  6. +1 −1 docs/ensureFile.md
  7. +1 −1 docs/ensureLink.md
  8. +1 −1 docs/ensureSymlink-sync.md
  9. +1 −1 docs/ensureSymlink.md
  10. +1 −1 docs/move-sync.md
  11. +1 −1 docs/move.md
  12. +1 −1 docs/outputFile-sync.md
  13. +1 −1 docs/outputFile.md
  14. +1 −1 docs/outputJson-sync.md
  15. +1 −1 docs/outputJson.md
  16. +1 −1 docs/readJson-sync.md
  17. +1 −1 docs/readJson.md
  18. +1 −1 docs/remove.md
  19. +1 −1 docs/writeJson-sync.md
  20. +1 −1 docs/writeJson.md
  21. +1 −1 lib/copy-sync/__tests__/broken-symlink.test.js
  22. +23 −30 lib/copy-sync/__tests__/copy-sync-case-insensitive-paths.test.js
  23. +2 −2 lib/copy-sync/__tests__/copy-sync-dir.test.js
  24. +1 −1 lib/copy-sync/__tests__/copy-sync-file.test.js
  25. +4 −3 lib/copy-sync/__tests__/{copy-sync-preserve-time.test.js → copy-sync-preserve-timestamp.test.js}
  26. +1 −1 lib/copy-sync/__tests__/copy-sync-prevent-copying-identical.test.js
  27. +51 −5 lib/copy-sync/__tests__/copy-sync-prevent-copying-into-itself.test.js
  28. +4 −5 lib/copy-sync/__tests__/copy-sync-readonly-dir.test.js
  29. +3 −4 lib/copy-sync/__tests__/symlink.test.js
  30. +15 −42 lib/copy-sync/copy-sync.js
  31. +18 −25 lib/copy/__tests__/copy-case-insensitive-paths.test.js
  32. +1 −1 lib/copy/__tests__/copy-gh-89.test.js
  33. +4 −3 lib/copy/__tests__/{copy-preserve-time.test.js → copy-preserve-timestamp.test.js}
  34. +1 −1 lib/copy/__tests__/copy-prevent-copying-identical.test.js
  35. +43 −5 lib/copy/__tests__/copy-prevent-copying-into-itself.test.js
  36. +1 −1 lib/copy/__tests__/copy-readonly-dir.test.js
  37. +9 −6 lib/copy/__tests__/copy.test.js
  38. +19 −51 lib/copy/copy.js
  39. +124 −0 lib/move-sync/__tests__/move-sync-case-insensitive-paths.test.js
  40. +271 −0 lib/move-sync/__tests__/move-sync-prevent-moving-identical.test.js
  41. +302 −91 lib/move-sync/__tests__/move-sync-prevent-moving-into-itself.test.js
  42. +31 −77 lib/move-sync/__tests__/move-sync.test.js
  43. +1 −113 lib/move-sync/index.js
  44. +49 −0 lib/move-sync/move-sync.js
  45. +108 −0 lib/move/__tests__/move-case-insensitive-paths.test.js
  46. +252 −0 lib/move/__tests__/move-prevent-moving-identical.test.js
  47. +253 −61 lib/move/__tests__/move-prevent-moving-into-itself.test.js
  48. +6 −4 lib/move/__tests__/move.test.js
  49. +1 −77 lib/move/index.js
  50. +67 −0 lib/move/move.js
  51. +2 −2 lib/remove/__tests__/remove.test.js
  52. +175 −0 lib/util/stat.js
  53. +2 −5 package.json
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
8.0.0 / 2019-05-11
------------------

**NOTE:** Node.js v6 support is depreciated, and will be dropped in the next major release.

- Use `renameSync()` under the hood in `moveSync()`
- Fix bug with bind-mounted directories in `copy*()` ([#613](https://github.com/jprichardson/node-fs-extra/issues/613), [#618](https://github.com/jprichardson/node-fs-extra/pull/618))
- Fix bug in `move()` with case-insensitive file systems
- Use `fs.stat()`'s `bigint` option in `copy*()` & `move*()` where possible ([#657](https://github.com/jprichardson/node-fs-extra/issues/657))

7.0.1 / 2018-11-07
------------------

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ I got tired of including `mkdirp`, `rimraf`, and `ncp` in most of my projects.
Installation
------------

npm install --save fs-extra
npm install fs-extra



2 changes: 1 addition & 1 deletion docs/copy-sync.md
Original file line number Diff line number Diff line change
@@ -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`.

2 changes: 1 addition & 1 deletion docs/copy.md
Original file line number Diff line number Diff line change
@@ -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`.

2 changes: 1 addition & 1 deletion docs/emptyDir.md
Original file line number Diff line number Diff line change
@@ -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.

2 changes: 1 addition & 1 deletion docs/ensureFile.md
Original file line number Diff line number Diff line change
@@ -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**.

2 changes: 1 addition & 1 deletion docs/ensureLink.md
Original file line number Diff line number Diff line change
@@ -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.

2 changes: 1 addition & 1 deletion docs/ensureSymlink-sync.md
Original file line number Diff line number Diff line change
@@ -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.

2 changes: 1 addition & 1 deletion docs/ensureSymlink.md
Original file line number Diff line number Diff line change
@@ -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.

2 changes: 1 addition & 1 deletion docs/move-sync.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# moveSync(src, dest, [options])
# moveSync(src, dest[, options])

Moves a file or directory, even across devices.

2 changes: 1 addition & 1 deletion docs/move.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# move(src, dest, [options, callback])
# move(src, dest[, options][, callback])

Moves a file or directory, even across devices.

2 changes: 1 addition & 1 deletion docs/outputFile-sync.md
Original file line number Diff line number Diff line change
@@ -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).

2 changes: 1 addition & 1 deletion docs/outputFile.md
Original file line number Diff line number Diff line change
@@ -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).

2 changes: 1 addition & 1 deletion docs/outputJson-sync.md
Original file line number Diff line number Diff line change
@@ -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.

2 changes: 1 addition & 1 deletion docs/outputJson.md
Original file line number Diff line number Diff line change
@@ -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.

2 changes: 1 addition & 1 deletion docs/readJson-sync.md
Original file line number Diff line number Diff line change
@@ -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).
2 changes: 1 addition & 1 deletion docs/readJson.md
Original file line number Diff line number Diff line change
@@ -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).
2 changes: 1 addition & 1 deletion docs/remove.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# remove(path, [callback])
# remove(path[, callback])

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

2 changes: 1 addition & 1 deletion docs/writeJson-sync.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# writeJsonSync(file, object, [options])
# writeJsonSync(file, object[, options])

Writes an object to a JSON file.

2 changes: 1 addition & 1 deletion docs/writeJson.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# writeJson(file, object, [options, callback])
# writeJson(file, object[, options][, callback])

Writes an object to a JSON file.

2 changes: 1 addition & 1 deletion lib/copy-sync/__tests__/broken-symlink.test.js
Original file line number Diff line number Diff line change
@@ -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')
53 changes: 23 additions & 30 deletions lib/copy-sync/__tests__/copy-sync-case-insensitive-paths.test.js
Original file line number Diff line number Diff line change
@@ -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 */

@@ -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', () => {
@@ -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)
@@ -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)
@@ -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)
}
})
@@ -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)
}
})
4 changes: 2 additions & 2 deletions lib/copy-sync/__tests__/copy-sync-dir.test.js
Original file line number Diff line number Diff line change
@@ -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')
@@ -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)

2 changes: 1 addition & 1 deletion lib/copy-sync/__tests__/copy-sync-file.test.js
Original file line number Diff line number Diff line change
@@ -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')
Original file line number Diff line number Diff line change
@@ -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 */

Original file line number Diff line number Diff line change
@@ -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 */
Original file line number Diff line number Diff line change
@@ -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 */
@@ -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')
@@ -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')
Loading