From 1a4ccc0572b050d88d17d6cbd67d54298f772ac3 Mon Sep 17 00:00:00 2001 From: Ryan Zimmerman Date: Fri, 14 Feb 2020 12:56:44 -0500 Subject: [PATCH] Port improvments to sync methods --- lib/util/stat.js | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/lib/util/stat.js b/lib/util/stat.js index 644e40b9..0b1c1b09 100644 --- a/lib/util/stat.js +++ b/lib/util/stat.js @@ -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([ @@ -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 @@ -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