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 d9f8ef9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/util/__tests__/utimes.test.js
Expand Up @@ -33,7 +33,7 @@ describe('utimes', () => {
fse.emptyDir(TEST_DIR, done)
// reset stubs
gracefulFsStub = {}
utimes = proxyquire('../utimes', { 'graceful-fs': gracefulFsStub })
utimes = proxyquire('../utimes', { '../fs': gracefulFsStub })
})

describe('utimesMillis()', () => {
Expand Down
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 d9f8ef9

Please sign in to comment.