Skip to content

Commit

Permalink
fs: replace finally with PromisePrototypeFinally
Browse files Browse the repository at this point in the history
  • Loading branch information
baruchiro committed Nov 8, 2020
1 parent f06f3c0 commit b3d82e0
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 @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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 = {
Expand Down

0 comments on commit b3d82e0

Please sign in to comment.