summaryrefslogtreecommitdiff
path: root/node_modules/fs-extra/lib/util/utimes.js
diff options
context:
space:
mode:
authorLinuxWizard42 <computerwizard@linuxmail.org>2022-10-12 22:54:37 +0300
committerLinuxWizard42 <computerwizard@linuxmail.org>2022-10-12 22:54:37 +0300
commit703e03aba33f234712206769f57717ba7d92d23d (patch)
tree0041f04ccb75bd5379c764e9fe42249fffe75fc3 /node_modules/fs-extra/lib/util/utimes.js
parentab6e257e6e9d9a483d7e86f220d8b209a2cd7753 (diff)
downloadFlashRunner-703e03aba33f234712206769f57717ba7d92d23d.tar.gz
FlashRunner-703e03aba33f234712206769f57717ba7d92d23d.tar.zst
Added export_allowed file to make repository visible in cgit
Diffstat (limited to 'node_modules/fs-extra/lib/util/utimes.js')
-rw-r--r--node_modules/fs-extra/lib/util/utimes.js72
1 files changed, 72 insertions, 0 deletions
diff --git a/node_modules/fs-extra/lib/util/utimes.js b/node_modules/fs-extra/lib/util/utimes.js
new file mode 100644
index 0000000..4c32099
--- /dev/null
+++ b/node_modules/fs-extra/lib/util/utimes.js
@@ -0,0 +1,72 @@
+'use strict'
+
+const fs = require('graceful-fs')
+const os = require('os')
+const path = require('path')
+
+// HFS, ext{2,3}, FAT do not, Node.js v0.10 does not
+function hasMillisResSync () {
+ let tmpfile = path.join('millis-test-sync' + Date.now().toString() + Math.random().toString().slice(2))
+ tmpfile = path.join(os.tmpdir(), tmpfile)
+
+ // 550 millis past UNIX epoch
+ const d = new Date(1435410243862)
+ fs.writeFileSync(tmpfile, 'https://github.com/jprichardson/node-fs-extra/pull/141')
+ const fd = fs.openSync(tmpfile, 'r+')
+ fs.futimesSync(fd, d, d)
+ fs.closeSync(fd)
+ return fs.statSync(tmpfile).mtime > 1435410243000
+}
+
+function hasMillisRes (callback) {
+ let tmpfile = path.join('millis-test' + Date.now().toString() + Math.random().toString().slice(2))
+ tmpfile = path.join(os.tmpdir(), tmpfile)
+
+ // 550 millis past UNIX epoch
+ const d = new Date(1435410243862)
+ fs.writeFile(tmpfile, 'https://github.com/jprichardson/node-fs-extra/pull/141', err => {
+ if (err) return callback(err)
+ fs.open(tmpfile, 'r+', (err, fd) => {
+ if (err) return callback(err)
+ fs.futimes(fd, d, d, err => {
+ if (err) return callback(err)
+ fs.close(fd, err => {
+ if (err) return callback(err)
+ fs.stat(tmpfile, (err, stats) => {
+ if (err) return callback(err)
+ callback(null, stats.mtime > 1435410243000)
+ })
+ })
+ })
+ })
+ })
+}
+
+function timeRemoveMillis (timestamp) {
+ if (typeof timestamp === 'number') {
+ return Math.floor(timestamp / 1000) * 1000
+ } else if (timestamp instanceof Date) {
+ return new Date(Math.floor(timestamp.getTime() / 1000) * 1000)
+ } else {
+ throw new Error('fs-extra: timeRemoveMillis() unknown parameter type')
+ }
+}
+
+function utimesMillis (path, atime, mtime, callback) {
+ // if (!HAS_MILLIS_RES) return fs.utimes(path, atime, mtime, callback)
+ fs.open(path, 'r+', (err, fd) => {
+ if (err) return callback(err)
+ fs.futimes(fd, atime, mtime, futimesErr => {
+ fs.close(fd, closeErr => {
+ if (callback) callback(futimesErr || closeErr)
+ })
+ })
+ })
+}
+
+module.exports = {
+ hasMillisRes,
+ hasMillisResSync,
+ timeRemoveMillis,
+ utimesMillis
+}