diff --git a/lib/util/__tests__/stat.test.js b/lib/util/__tests__/stat.test.js index 2b7de648d..58b3bd7f1 100644 --- a/lib/util/__tests__/stat.test.js +++ b/lib/util/__tests__/stat.test.js @@ -4,11 +4,8 @@ const fs = require(process.cwd()) const os = require('os') const path = require('path') const assert = require('assert') -const atLeastNode = require('at-least-node') const stat = require('../stat.js') -const NODE_VERSION_WITH_BIGINT = '10.5.0' - /* global beforeEach, afterEach, describe, it */ describe('util/stat', () => { @@ -21,7 +18,7 @@ describe('util/stat', () => { 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', () => { + describe('should use stats with bigint type', () => { it('stat.checkPaths()', () => { const src = path.join(TEST_DIR, 'src') const dest = path.join(TEST_DIR, 'dest') @@ -29,12 +26,7 @@ describe('util/stat', () => { fs.ensureFileSync(dest) stat.checkPaths(src, dest, 'copy', {}, (err, stats) => { assert.ifError(err) - const { srcStat } = stats - if (atLeastNode(NODE_VERSION_WITH_BIGINT)) { - assert.strictEqual(typeof srcStat.ino, 'bigint') - } else { - assert.strictEqual(typeof srcStat.ino, 'number') - } + assert.strictEqual(typeof stats.srcStat.ino, 'bigint') }) }) @@ -44,11 +36,7 @@ describe('util/stat', () => { fs.ensureFileSync(src) fs.ensureFileSync(dest) const { srcStat } = stat.checkPathsSync(src, dest, 'copy', {}) - if (atLeastNode(NODE_VERSION_WITH_BIGINT)) { - assert.strictEqual(typeof srcStat.ino, 'bigint') - } else { - assert.strictEqual(typeof srcStat.ino, 'number') - } + assert.strictEqual(typeof srcStat.ino, 'bigint') }) }) diff --git a/lib/util/stat.js b/lib/util/stat.js index 4f4ce98e5..0ed5aecf7 100644 --- a/lib/util/stat.js +++ b/lib/util/stat.js @@ -3,16 +3,11 @@ const fs = require('../fs') const path = require('path') const util = require('util') -const atLeastNode = require('at-least-node') - -const nodeSupportsBigInt = atLeastNode('10.5.0') -const stat = (file) => nodeSupportsBigInt ? fs.stat(file, { bigint: true }) : fs.stat(file) -const lstat = (file) => nodeSupportsBigInt ? fs.lstat(file, { bigint: true }) : fs.lstat(file) -const statSync = (file) => nodeSupportsBigInt ? fs.statSync(file, { bigint: true }) : fs.statSync(file) -const lstatSync = (file) => nodeSupportsBigInt ? fs.lstatSync(file, { bigint: true }) : fs.lstatSync(file) function getStats (src, dest, opts) { - const statFunc = opts.dereference ? stat : lstat + const statFunc = opts.dereference + ? (file) => fs.stat(file, { bigint: true }) + : (file) => fs.lstat(file, { bigint: true }) return Promise.all([ statFunc(src), statFunc(dest).catch(err => { @@ -24,7 +19,9 @@ function getStats (src, dest, opts) { function getStatsSync (src, dest, opts) { let destStat - const statFunc = opts.dereference ? statSync : lstatSync + const statFunc = opts.dereference + ? (file) => fs.statSync(file, { bigint: true }) + : (file) => fs.lstatSync(file, { bigint: true }) const srcStat = statFunc(src) try { destStat = statFunc(dest) @@ -102,7 +99,7 @@ function checkParentPaths (src, srcStat, dest, funcName, 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() - const callback = (err, destStat) => { + fs.stat(destParent, { bigint: true }, (err, destStat) => { if (err) { if (err.code === 'ENOENT') return cb() return cb(err) @@ -111,9 +108,7 @@ function checkParentPaths (src, srcStat, dest, funcName, cb) { return cb(new Error(errMsg(src, dest, funcName))) } return checkParentPaths(src, srcStat, destParent, funcName, cb) - } - if (nodeSupportsBigInt) fs.stat(destParent, { bigint: true }, callback) - else fs.stat(destParent, callback) + }) } function checkParentPathsSync (src, srcStat, dest, funcName) { @@ -122,7 +117,7 @@ function checkParentPathsSync (src, srcStat, dest, funcName) { if (destParent === srcParent || destParent === path.parse(destParent).root) return let destStat try { - destStat = statSync(destParent) + destStat = fs.statSync(destParent, { bigint: true }) } catch (err) { if (err.code === 'ENOENT') return throw err @@ -134,26 +129,7 @@ function checkParentPathsSync (src, srcStat, dest, funcName) { } function areIdentical (srcStat, destStat) { - if (destStat.ino && destStat.dev && destStat.ino === srcStat.ino && destStat.dev === srcStat.dev) { - if (nodeSupportsBigInt || destStat.ino < Number.MAX_SAFE_INTEGER) { - // definitive answer - return true - } - // Use additional heuristics if we can't use 'bigint'. - // Different 'ino' could be represented the same if they are >= Number.MAX_SAFE_INTEGER - // See issue 657 - if (destStat.size === srcStat.size && - destStat.mode === srcStat.mode && - destStat.nlink === srcStat.nlink && - destStat.atimeMs === srcStat.atimeMs && - destStat.mtimeMs === srcStat.mtimeMs && - destStat.ctimeMs === srcStat.ctimeMs && - destStat.birthtimeMs === srcStat.birthtimeMs) { - // heuristic answer - return true - } - } - return false + return destStat.ino && destStat.dev && destStat.ino === srcStat.ino && destStat.dev === srcStat.dev } // return true if dest is a subdir of src, otherwise false.