Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! make it work with closures as well
  • Loading branch information
sapphi-red committed Oct 12, 2023
commit 017ac3c2e96bf3e3992caba23ba5acdf9bba6a41
110 changes: 55 additions & 55 deletions lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,9 @@ async function access(path, mode = F_OK) {
path = getValidatedPath(path);

mode = getValidMode(mode, 'access');
return binding.access(pathModule.toNamespacedPath(path), mode,
kUsePromises)
.catch(handleErrorFromBinding);
return await binding.access(pathModule.toNamespacedPath(path), mode,
kUsePromises)
.catch(handleErrorFromBinding);
}

async function cp(src, dest, options) {
Expand All @@ -598,11 +598,11 @@ async function copyFile(src, dest, mode) {
src = getValidatedPath(src, 'src');
dest = getValidatedPath(dest, 'dest');
mode = getValidMode(mode, 'copyFile');
return binding.copyFile(pathModule.toNamespacedPath(src),
pathModule.toNamespacedPath(dest),
mode,
kUsePromises)
.catch(handleErrorFromBinding);
return await binding.copyFile(pathModule.toNamespacedPath(src),
pathModule.toNamespacedPath(dest),
mode,
kUsePromises)
.catch(handleErrorFromBinding);
}

// Note that unlike fs.open() which uses numeric file descriptors,
Expand Down Expand Up @@ -744,10 +744,10 @@ async function writev(handle, buffers, position) {
async function rename(oldPath, newPath) {
oldPath = getValidatedPath(oldPath, 'oldPath');
newPath = getValidatedPath(newPath, 'newPath');
return binding.rename(pathModule.toNamespacedPath(oldPath),
pathModule.toNamespacedPath(newPath),
kUsePromises)
.catch(handleErrorFromBinding);
return await binding.rename(pathModule.toNamespacedPath(oldPath),
pathModule.toNamespacedPath(newPath),
kUsePromises)
.catch(handleErrorFromBinding);
}

async function truncate(path, len = 0) {
Expand All @@ -758,7 +758,7 @@ async function truncate(path, len = 0) {
async function ftruncate(handle, len = 0) {
validateInteger(len, 'len');
len = MathMax(0, len);
return binding.ftruncate(handle.fd, len, kUsePromises).catch(handleErrorFromBinding);
return await binding.ftruncate(handle.fd, len, kUsePromises).catch(handleErrorFromBinding);
}

async function rm(path, options) {
Expand All @@ -779,15 +779,15 @@ async function rmdir(path, options) {
}
}

return binding.rmdir(path, kUsePromises).catch(handleErrorFromBinding);
return await binding.rmdir(path, kUsePromises).catch(handleErrorFromBinding);
}

async function fdatasync(handle) {
return binding.fdatasync(handle.fd, kUsePromises).catch(handleErrorFromBinding);
return await binding.fdatasync(handle.fd, kUsePromises).catch(handleErrorFromBinding);
}

async function fsync(handle) {
return binding.fsync(handle.fd, kUsePromises).catch(handleErrorFromBinding);
return await binding.fsync(handle.fd, kUsePromises).catch(handleErrorFromBinding);
}

async function mkdir(path, options) {
Expand All @@ -801,10 +801,10 @@ async function mkdir(path, options) {
path = getValidatedPath(path);
validateBoolean(recursive, 'options.recursive');

return binding.mkdir(pathModule.toNamespacedPath(path),
parseFileMode(mode, 'mode', 0o777), recursive,
kUsePromises)
.catch(handleErrorFromBinding);
return await binding.mkdir(pathModule.toNamespacedPath(path),
parseFileMode(mode, 'mode', 0o777), recursive,
kUsePromises)
.catch(handleErrorFromBinding);
}

async function readdirRecursive(originalPath, options) {
Expand Down Expand Up @@ -890,9 +890,9 @@ async function readdir(path, options) {
async function readlink(path, options) {
options = getOptions(options);
path = getValidatedPath(path, 'oldPath');
return binding.readlink(pathModule.toNamespacedPath(path),
options.encoding, kUsePromises)
.catch(handleErrorFromBinding);
return await binding.readlink(pathModule.toNamespacedPath(path),
options.encoding, kUsePromises)
.catch(handleErrorFromBinding);
}

async function symlink(target, path, type_) {
Expand All @@ -908,11 +908,11 @@ async function symlink(target, path, type_) {
}
target = getValidatedPath(target, 'target');
path = getValidatedPath(path);
return binding.symlink(preprocessSymlinkDestination(target, type, path),
pathModule.toNamespacedPath(path),
stringToSymlinkType(type),
kUsePromises)
.catch(handleErrorFromBinding);
return await binding.symlink(preprocessSymlinkDestination(target, type, path),
pathModule.toNamespacedPath(path),
stringToSymlinkType(type),
kUsePromises)
.catch(handleErrorFromBinding);
}

async function fstat(handle, options = { bigint: false }) {
Expand Down Expand Up @@ -947,26 +947,26 @@ async function statfs(path, options = { bigint: false }) {
async function link(existingPath, newPath) {
existingPath = getValidatedPath(existingPath, 'existingPath');
newPath = getValidatedPath(newPath, 'newPath');
return binding.link(pathModule.toNamespacedPath(existingPath),
pathModule.toNamespacedPath(newPath),
kUsePromises)
.catch(handleErrorFromBinding);
return await binding.link(pathModule.toNamespacedPath(existingPath),
pathModule.toNamespacedPath(newPath),
kUsePromises)
.catch(handleErrorFromBinding);
}

async function unlink(path) {
path = getValidatedPath(path);
return binding.unlink(pathModule.toNamespacedPath(path), kUsePromises).catch(handleErrorFromBinding);
return await binding.unlink(pathModule.toNamespacedPath(path), kUsePromises).catch(handleErrorFromBinding);
}

async function fchmod(handle, mode) {
mode = parseFileMode(mode, 'mode');
return binding.fchmod(handle.fd, mode, kUsePromises).catch(handleErrorFromBinding);
return await binding.fchmod(handle.fd, mode, kUsePromises).catch(handleErrorFromBinding);
}

async function chmod(path, mode) {
path = getValidatedPath(path);
mode = parseFileMode(mode, 'mode');
return binding.chmod(pathModule.toNamespacedPath(path), mode, kUsePromises).catch(handleErrorFromBinding);
return await binding.chmod(pathModule.toNamespacedPath(path), mode, kUsePromises).catch(handleErrorFromBinding);
}

async function lchmod(path, mode) {
Expand All @@ -981,54 +981,54 @@ async function lchown(path, uid, gid) {
path = getValidatedPath(path);
validateInteger(uid, 'uid', -1, kMaxUserId);
validateInteger(gid, 'gid', -1, kMaxUserId);
return binding.lchown(pathModule.toNamespacedPath(path),
uid, gid, kUsePromises)
.catch(handleErrorFromBinding);
return await binding.lchown(pathModule.toNamespacedPath(path),
uid, gid, kUsePromises)
.catch(handleErrorFromBinding);
}

async function fchown(handle, uid, gid) {
validateInteger(uid, 'uid', -1, kMaxUserId);
validateInteger(gid, 'gid', -1, kMaxUserId);
return binding.fchown(handle.fd, uid, gid, kUsePromises).catch(handleErrorFromBinding);
return await binding.fchown(handle.fd, uid, gid, kUsePromises).catch(handleErrorFromBinding);
}

async function chown(path, uid, gid) {
path = getValidatedPath(path);
validateInteger(uid, 'uid', -1, kMaxUserId);
validateInteger(gid, 'gid', -1, kMaxUserId);
return binding.chown(pathModule.toNamespacedPath(path),
uid, gid, kUsePromises)
.catch(handleErrorFromBinding);
return await binding.chown(pathModule.toNamespacedPath(path),
uid, gid, kUsePromises)
.catch(handleErrorFromBinding);
}

async function utimes(path, atime, mtime) {
path = getValidatedPath(path);
return binding.utimes(pathModule.toNamespacedPath(path),
toUnixTimestamp(atime),
toUnixTimestamp(mtime),
kUsePromises)
.catch(handleErrorFromBinding);
return await binding.utimes(pathModule.toNamespacedPath(path),
toUnixTimestamp(atime),
toUnixTimestamp(mtime),
kUsePromises)
.catch(handleErrorFromBinding);
}

async function futimes(handle, atime, mtime) {
atime = toUnixTimestamp(atime, 'atime');
mtime = toUnixTimestamp(mtime, 'mtime');
return binding.futimes(handle.fd, atime, mtime, kUsePromises).catch(handleErrorFromBinding);
return await binding.futimes(handle.fd, atime, mtime, kUsePromises).catch(handleErrorFromBinding);
}

async function lutimes(path, atime, mtime) {
path = getValidatedPath(path);
return binding.lutimes(pathModule.toNamespacedPath(path),
toUnixTimestamp(atime),
toUnixTimestamp(mtime),
kUsePromises)
.catch(handleErrorFromBinding);
return await binding.lutimes(pathModule.toNamespacedPath(path),
toUnixTimestamp(atime),
toUnixTimestamp(mtime),
kUsePromises)
.catch(handleErrorFromBinding);
}

async function realpath(path, options) {
options = getOptions(options);
path = getValidatedPath(path);
return binding.realpath(path, options.encoding, kUsePromises).catch(handleErrorFromBinding);
return await binding.realpath(path, options.encoding, kUsePromises).catch(handleErrorFromBinding);
}

async function mkdtemp(prefix, options) {
Expand All @@ -1044,7 +1044,7 @@ async function mkdtemp(prefix, options) {
path = Buffer.concat([prefix, Buffer.from('XXXXXX')]);
}

return binding.mkdtemp(path, options.encoding, kUsePromises).catch(handleErrorFromBinding);
return await binding.mkdtemp(path, options.encoding, kUsePromises).catch(handleErrorFromBinding);
}

async function writeFile(path, data, options) {
Expand Down
6 changes: 5 additions & 1 deletion test/parallel/test-fs-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,13 @@ fs.promises.access(readOnlyFile, fs.constants.R_OK)
assert.strictEqual(err.code, 'ENOENT');
assert.strictEqual(err.path, doesNotExist);
};
const expectedErrorPromise = (err) => {
expectedError(err);
assert.match(err.stack, /at async Object\.access/);
};
fs.access(doesNotExist, common.mustCall(expectedError));
fs.promises.access(doesNotExist)
.then(common.mustNotCall(), common.mustCall(expectedError))
.then(common.mustNotCall(), common.mustCall(expectedErrorPromise))
.catch(throwNextTick);
}

Expand Down