From 148bc33347266a0293d52859cbf9580ade9b6cbe 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 3790cdf2bc2b22..2c0b26f2dca01e 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -406,6 +406,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)`