Skip to content

Commit

Permalink
Use promisfied fs API from lib/fs
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Oct 20, 2023
1 parent e125aa2 commit a948dc0
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions lib/util/utimes.js
@@ -1,11 +1,6 @@
'use strict'

const fs = require('graceful-fs')
const { promisify } = require('util')

const open = promisify(fs.open)
const futimes = promisify(fs.futimes)
const close = promisify(fs.close)
const fs = require('../fs')

// TODO: remove `utimesMillis` once all internal usage has switched to the Promise-based `utimesMillisAsync` API
function utimesMillis (path, atime, mtime, callback) {
Expand All @@ -22,19 +17,19 @@ function utimesMillis (path, atime, mtime, callback) {

async function utimesMillisAsync (path, atime, mtime) {
// if (!HAS_MILLIS_RES) return fs.utimes(path, atime, mtime, callback)
const fd = await open(path, 'r+')
const fd = await fs.open(path, 'r+')

let futimesErr = null
try {
await futimes(fd, atime, mtime)
await fs.futimes(fd, atime, mtime)
} catch (e) {
futimesErr = e
}

let closeErr = null

try {
await close(fd)
await fs.close(fd)
} catch (e) {
closeErr = e
}
Expand Down

0 comments on commit a948dc0

Please sign in to comment.