fs: close file descriptor of promisified truncate

PR-URL: https://github.com/nodejs/node/pull/28858
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
João Reis 2019-07-30 07:45:31 +01:00 committed by Rich Trott
parent d3f20a4725
commit eadc3850fe

View File

@ -264,7 +264,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) {