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: 8.0.0
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: 32a65ffd9111829dbba15d79f1d27519c7dc96a6
Choose a head ref
  • 4 commits
  • 4 files changed
  • 2 contributors

Commits on May 13, 2019

  1. Copy the full SHA
    72278dc View commit details
  2. Copy the full SHA
    23b0c0c View commit details
  3. Merge pull request #679 from jprichardson/fix-max-call-stack

    util/stat: fix max call stack size exceeded
    manidlou authored May 13, 2019

    Verified

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

    manidlou committed May 13, 2019
    Copy the full SHA
    32a65ff View commit details
Showing with 93 additions and 9 deletions.
  1. +6 −1 CHANGELOG.md
  2. +80 −0 lib/util/__tests__/stat.test.js
  3. +6 −7 lib/util/stat.js
  4. +1 −1 package.json
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
8.0.1 / 2019-05-13
------------------

- Fix bug `Maximum call stack size exceeded` error in `util/stat` ([#679](https://github.com/jprichardson/node-fs-extra/pull/679))

8.0.0 / 2019-05-11
------------------

**NOTE:** Node.js v6 support is depreciated, and will be dropped in the next major release.
**NOTE:** Node.js v6 support is deprecated, 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))
80 changes: 80 additions & 0 deletions lib/util/__tests__/stat.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
'use strict'

const fs = require(process.cwd())
const os = require('os')
const path = require('path')
const assert = require('assert')
const semver = require('semver')
const stat = require('../stat.js')

const NODE_VERSION_WITH_BIGINT = '10.5.0'

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

describe('util/stat', () => {
let TEST_DIR

beforeEach(done => {
TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'util-stat')
fs.emptyDir(TEST_DIR, done)
})

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

describe('should use stats with bigint type for node versions >= 10.5.0 and number type for older versions', done => {
it('stat.checkPaths()', () => {
const nodeVersion = process.versions.node
const src = path.join(TEST_DIR, 'src')
const dest = path.join(TEST_DIR, 'dest')
fs.ensureFileSync(src)
fs.ensureFileSync(dest)
stat.checkPaths(src, dest, 'copy', (err, stats) => {
assert.ifError(err)
const { srcStat } = stats
if (semver.gte(nodeVersion, NODE_VERSION_WITH_BIGINT)) {
assert.strictEqual(typeof srcStat.ino, 'bigint')
} else {
assert.strictEqual(typeof srcStat.ino, 'number')
}
})
})

it('stat.checkPathsSync()', () => {
const nodeVersion = process.versions.node
const src = path.join(TEST_DIR, 'src')
const dest = path.join(TEST_DIR, 'dest')
fs.ensureFileSync(src)
fs.ensureFileSync(dest)
const { srcStat } = stat.checkPathsSync(src, dest, 'copy')
if (semver.gte(nodeVersion, NODE_VERSION_WITH_BIGINT)) {
assert.strictEqual(typeof srcStat.ino, 'bigint')
} else {
assert.strictEqual(typeof srcStat.ino, 'number')
}
})
})

describe('should stop at src or root path and not throw max call stack size error', done => {
it('stat.checkParentPaths()', () => {
const src = path.join(TEST_DIR, 'src')
let dest = path.join(TEST_DIR, 'dest')
fs.ensureFileSync(src)
fs.ensureFileSync(dest)
dest = path.basename(dest)
const srcStat = fs.statSync(src)
stat.checkParentPaths(src, srcStat, dest, 'copy', err => {
assert.ifError(err)
})
})

it('stat.checkParentPathsSync()', () => {
const src = path.join(TEST_DIR, 'src')
let dest = path.join(TEST_DIR, 'dest')
fs.ensureFileSync(src)
fs.ensureFileSync(dest)
dest = path.basename(dest)
const srcStat = fs.statSync(src)
stat.checkParentPathsSync(src, srcStat, dest, 'copy')
})
})
})
13 changes: 6 additions & 7 deletions lib/util/stat.js
Original file line number Diff line number Diff line change
@@ -104,11 +104,9 @@ function checkPathsSync (src, dest, funcName) {
// checks the src and dest inodes. It starts from the deepest
// parent and stops once it reaches the src parent or the root path.
function checkParentPaths (src, srcStat, dest, funcName, cb) {
const destParent = path.dirname(dest)
if (destParent &&
(destParent === path.dirname(src) ||
destParent === path.parse(destParent).root)
) return cb()
const srcParent = path.resolve(path.dirname(src))
const destParent = path.resolve(path.dirname(dest))
if (destParent === srcParent || destParent === path.parse(destParent).root) return cb()
if (nodeSupportsBigInt()) {
fs.stat(destParent, { bigint: true }, (err, destStat) => {
if (err) {
@@ -135,8 +133,9 @@ function checkParentPaths (src, srcStat, dest, funcName, cb) {
}

function checkParentPathsSync (src, srcStat, dest, funcName) {
const destParent = path.dirname(dest)
if (destParent && (destParent === path.dirname(src) || destParent === path.parse(destParent).root)) return
const srcParent = path.resolve(path.dirname(src))
const destParent = path.resolve(path.dirname(dest))
if (destParent === srcParent || destParent === path.parse(destParent).root) return
let destStat
try {
if (nodeSupportsBigInt()) {
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fs-extra",
"version": "8.0.0",
"version": "8.0.1",
"description": "fs-extra contains methods that aren't included in the vanilla Node.js fs package. Such as mkdir -p, cp -r, and rm -rf.",
"engines": {
"node": ">=6 <7 || >=8"