Skip to content

Commit

Permalink
Port improvments to sync methods
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanZim committed Feb 14, 2020
1 parent 02df72f commit 1a4ccc0
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions lib/util/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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 statSync = (file) => nodeSupportsBigInt ? fs.statSync(file, { bigint: true }) : fs.statSync(file)

function getStats (src, dest) {
return Promise.all([
Expand All @@ -19,18 +20,10 @@ function getStats (src, dest) {
}

function getStatsSync (src, dest) {
let srcStat, destStat
if (nodeSupportsBigInt) {
srcStat = fs.statSync(src, { bigint: true })
} else {
srcStat = fs.statSync(src)
}
let destStat
const srcStat = statSync(src)
try {
if (nodeSupportsBigInt) {
destStat = fs.statSync(dest, { bigint: true })
} else {
destStat = fs.statSync(dest)
}
destStat = statSync(dest)
} catch (err) {
if (err.code === 'ENOENT') return { srcStat, destStat: null }
throw err
Expand Down Expand Up @@ -91,11 +84,7 @@ function checkParentPathsSync (src, srcStat, dest, funcName) {
if (destParent === srcParent || destParent === path.parse(destParent).root) return
let destStat
try {
if (nodeSupportsBigInt) {
destStat = fs.statSync(destParent, { bigint: true })
} else {
destStat = fs.statSync(destParent)
}
destStat = statSync(destParent)
} catch (err) {
if (err.code === 'ENOENT') return
throw err
Expand Down

0 comments on commit 1a4ccc0

Please sign in to comment.