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 <rtrott@gmail.com>
  Reviewed-By: Colin Ihrig <cjihrig@gmail.com>

PR-URL: #34239
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
  • Loading branch information
joaocgreis authored and jasnell committed Jul 9, 2020
1 parent d547d1c commit 04fa6d6
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 04fa6d6

Please sign in to comment.