From affa71001b81d9a061f8c005fa5e6879dcc6aeaf Mon Sep 17 00:00:00 2001 From: "Baruch Odem (Rothkoff)" Date: Fri, 6 Nov 2020 14:47:34 +0200 Subject: [PATCH] fs: replace finally with PromisePrototypeFinally https://github.com/nodejs/node/pull/35993#discussion_r518703665 PR-URL: https://github.com/nodejs/node/pull/35995 Reviewed-By: Antoine du Hamel Reviewed-By: Rich Trott --- lib/internal/fs/promises.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js index a46a8b75992c4e..bec0b5ebbc64e2 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -15,6 +15,7 @@ const { MathMin, NumberIsSafeInteger, Promise, + PromisePrototypeFinally, PromiseResolve, Symbol, Uint8Array, @@ -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) { @@ -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) { @@ -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) { @@ -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 = {