From b38d6b475b66e030bafca9ae597b1eefdb8eda46 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Mon, 22 Feb 2021 13:19:14 -0800 Subject: [PATCH] fs: fixup negative length in fs.truncate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `fs.ftruncate`, `fsPromises.truncate`, and `fsPromises.ftruncate` all adjust negative lengths to 0 before invoking the system call. `fs.truncate()` was the one outlier. This "fixes" https://github.com/nodejs/node/issues/35632 but in the opposite direction than discussed in the issue -- specifically by removing an EINVAL error from one function rather than adding it to another. Signed-off-by: James M Snell Fixes: https://github.com/nodejs/node/issues/35632 PR-URL: https://github.com/nodejs/node/pull/37483 Reviewed-By: Darshan Sen Reviewed-By: Juan José Arboleda Reviewed-By: Luigi Pinca --- doc/api/fs.md | 4 ++++ lib/fs.js | 1 + test/parallel/test-fs-truncate.js | 16 ++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/doc/api/fs.md b/doc/api/fs.md index f4679126307a34..be2062fe662886 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -398,6 +398,8 @@ try { If the file previously was shorter than `len` bytes, it is extended, and the extended part is filled with null bytes (`'\0'`): +If `len` is negative then `0` will be used. + #### `filehandle.utimes(atime, mtime)`