From 7ef9c707e9815fdd56e3bf6ab5e89c51c52f5fff 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 df80efb514d2dc..de071879af2f47 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, @@ -431,7 +432,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) { @@ -559,7 +560,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) { @@ -635,7 +636,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) { @@ -653,7 +654,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 = {