Skip to content

Commit

Permalink
fs: close file descriptor of promisified truncate
Browse files Browse the repository at this point in the history
Original PR:
  PR-URL: #28858
  Reviewed-By: Rich Trott <[email protected]>
  Reviewed-By: Colin Ihrig <[email protected]>

PR-URL: #34239
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
  • Loading branch information
joaocgreis authored and codebytere committed Jul 14, 2020
1 parent 6db21cc commit 7aac983
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ async function rename(oldPath, newPath) {
}

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

async function ftruncate(handle, len = 0) {
Expand Down

0 comments on commit 7aac983

Please sign in to comment.