Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor copy API in async/await #1021

Merged
merged 15 commits into from Oct 24, 2023
14 changes: 8 additions & 6 deletions lib/util/__tests__/utimes.test.js
Expand Up @@ -6,6 +6,8 @@ const fse = require('../..')
const path = require('path')
const assert = require('assert')
const proxyquire = require('proxyquire')
const u = require('universalify').fromCallback

let gracefulFsStub
let utimes

Expand Down Expand Up @@ -68,25 +70,25 @@ describe('utimes', () => {
it('should close open file desciptors after encountering an error', done => {
const fakeFd = Math.random()

gracefulFsStub.open = (pathIgnored, flagsIgnored, modeIgnored, callback) => {
gracefulFsStub.open = u((pathIgnored, flagsIgnored, modeIgnored, callback) => {
Copy link
Contributor Author

@SukkaW SukkaW Oct 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The gracefulFsStub needs to be universalify as the utimesMillis is now Promise-based and then universalized.

if (typeof modeIgnored === 'function') callback = modeIgnored
process.nextTick(() => callback(null, fakeFd))
}
})

let closeCalled = false
gracefulFsStub.close = (fd, callback) => {
gracefulFsStub.close = u((fd, callback) => {
assert.strictEqual(fd, fakeFd)
closeCalled = true
if (callback) process.nextTick(callback)
}
})

let testError
gracefulFsStub.futimes = (fd, atimeIgnored, mtimeIgnored, callback) => {
gracefulFsStub.futimes = u((fd, atimeIgnored, mtimeIgnored, callback) => {
process.nextTick(() => {
testError = new Error('A test error')
callback(testError)
})
}
})

utimes.utimesMillis('ignored', 'ignored', 'ignored', err => {
assert.strictEqual(err, testError)
Expand Down
2 changes: 1 addition & 1 deletion lib/util/utimes.js
Expand Up @@ -3,7 +3,7 @@
const fs = require('../fs')
const u = require('universalify').fromPromise

async function utimesMillis (path, atime, mtime) {
async function utimesMillis (path, atime, mtime, cb) {
SukkaW marked this conversation as resolved.
Show resolved Hide resolved
// if (!HAS_MILLIS_RES) return fs.utimes(path, atime, mtime, callback)
const fd = await fs.open(path, 'r+')

Expand Down