From 036c6f406ccd10bc39b07607fa44879ae5c165c8 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 `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 --- doc/api/fs.md | 4 ++++ lib/fs.js | 1 + test/parallel/test-fs-truncate.js | 7 +++++++ 3 files changed, 12 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)`