Skip to content

Commit

Permalink
fs: replace finally with PromisePrototypeFinally
Browse files Browse the repository at this point in the history
#35993 (comment)

PR-URL: #35995
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
baruchiro authored and BethGriggs committed Dec 15, 2020
1 parent 0477e00 commit 7c3b6f1
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const {
MathMin,
NumberIsSafeInteger,
Promise,
PromisePrototypeFinally,
PromiseResolve,
Symbol,
Uint8Array,
Expand Down Expand Up @@ -410,7 +411,7 @@ async function rename(oldPath, newPath) {

async function truncate(path, len = 0) {
const fd = await open(path, 'r+');
return ftruncate(fd, len).finally(fd.close);
return PromisePrototypeFinally(ftruncate(fd, len), fd.close);
}

async function ftruncate(handle, len = 0) {
Expand Down Expand Up @@ -538,7 +539,7 @@ async function lchmod(path, mode) {
throw new ERR_METHOD_NOT_IMPLEMENTED('lchmod()');

const fd = await open(path, O_WRONLY | O_SYMLINK);
return fchmod(fd, mode).finally(fd.close);
return PromisePrototypeFinally(fchmod(fd, mode), fd.close);
}

async function lchown(path, uid, gid) {
Expand Down Expand Up @@ -614,7 +615,7 @@ async function writeFile(path, data, options) {
return writeFileHandle(path, data);

const fd = await open(path, flag, options.mode);
return writeFileHandle(fd, data).finally(fd.close);
return PromisePrototypeFinally(writeFileHandle(fd, data), fd.close);
}

async function appendFile(path, data, options) {
Expand All @@ -632,7 +633,7 @@ async function readFile(path, options) {
return readFileHandle(path, options);

const fd = await open(path, flag, 0o666);
return readFileHandle(fd, options).finally(fd.close);
return PromisePrototypeFinally(readFileHandle(fd, options), fd.close);
}

module.exports = {
Expand Down

0 comments on commit 7c3b6f1

Please sign in to comment.