From 148f2af59da55cd5fa417a31d1da65fb6abedfb1 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Tue, 7 Jan 2020 10:44:38 +0100 Subject: [PATCH] fix stat times not being set --- index.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index f939e6d..ea6ae9a 100644 --- a/index.js +++ b/index.js @@ -689,6 +689,12 @@ function getDoubleInt (arr, idx) { return num } +function toDateMS (st) { + if (typeof st === 'number') return st + if (!st) return Date.now() + return st.getTime() +} + function getStatArray (stat) { const ints = new Uint32Array(16) @@ -702,9 +708,9 @@ function getStatArray (stat) { ints[7] = (stat && stat.rdev) || 0 ints[8] = (stat && stat.blksize) || 0 ints[9] = (stat && stat.blocks) || 0 - setDoubleInt(ints, 10, (stat && stat.atim) || Date.now()) - setDoubleInt(ints, 12, (stat && stat.atim) || Date.now()) - setDoubleInt(ints, 14, (stat && stat.atim) || Date.now()) + setDoubleInt(ints, 10, toDateMS(stat && stat.atime)) + setDoubleInt(ints, 12, toDateMS(stat && stat.ctime)) + setDoubleInt(ints, 14, toDateMS(stat && stat.mtime)) return ints }