From c9c62d843520dd086601fc12c05d36ad9bb1c4de Mon Sep 17 00:00:00 2001 From: JPeer264 Date: Fri, 17 Feb 2017 23:06:27 +0100 Subject: [PATCH] Refactor utimes --- lib/util/utimes.js | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/lib/util/utimes.js b/lib/util/utimes.js index 118f8a7d..4c320993 100644 --- a/lib/util/utimes.js +++ b/lib/util/utimes.js @@ -1,36 +1,38 @@ -var fs = require('graceful-fs') -var path = require('path') -var os = require('os') +'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 () { - var tmpfile = path.join('millis-test-sync' + Date.now().toString() + Math.random().toString().slice(2)) + 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 - var d = new Date(1435410243862) + const d = new Date(1435410243862) fs.writeFileSync(tmpfile, 'https://github.com/jprichardson/node-fs-extra/pull/141') - var fd = fs.openSync(tmpfile, 'r+') + const fd = fs.openSync(tmpfile, 'r+') fs.futimesSync(fd, d, d) fs.closeSync(fd) return fs.statSync(tmpfile).mtime > 1435410243000 } function hasMillisRes (callback) { - var tmpfile = path.join('millis-test' + Date.now().toString() + Math.random().toString().slice(2)) + 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 - var d = new Date(1435410243862) - fs.writeFile(tmpfile, 'https://github.com/jprichardson/node-fs-extra/pull/141', function (err) { + 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+', function (err, fd) { + fs.open(tmpfile, 'r+', (err, fd) => { if (err) return callback(err) - fs.futimes(fd, d, d, function (err) { + fs.futimes(fd, d, d, err => { if (err) return callback(err) - fs.close(fd, function (err) { + fs.close(fd, err => { if (err) return callback(err) - fs.stat(tmpfile, function (err, stats) { + fs.stat(tmpfile, (err, stats) => { if (err) return callback(err) callback(null, stats.mtime > 1435410243000) }) @@ -52,10 +54,10 @@ function timeRemoveMillis (timestamp) { function utimesMillis (path, atime, mtime, callback) { // if (!HAS_MILLIS_RES) return fs.utimes(path, atime, mtime, callback) - fs.open(path, 'r+', function (err, fd) { + fs.open(path, 'r+', (err, fd) => { if (err) return callback(err) - fs.futimes(fd, atime, mtime, function (futimesErr) { - fs.close(fd, function (closeErr) { + fs.futimes(fd, atime, mtime, futimesErr => { + fs.close(fd, closeErr => { if (callback) callback(futimesErr || closeErr) }) }) @@ -63,8 +65,8 @@ function utimesMillis (path, atime, mtime, callback) { } module.exports = { - hasMillisRes: hasMillisRes, - hasMillisResSync: hasMillisResSync, - timeRemoveMillis: timeRemoveMillis, - utimesMillis: utimesMillis + hasMillisRes, + hasMillisResSync, + timeRemoveMillis, + utimesMillis }