fs: adjust truncate mode from `r+` to `a`
This PR changes flags in fsPromises.truncate(path[, len])
, fs.truncate(path[, len], callback)
, and fs.truncateSync(path[, len])
from r+
to a
.
This change:
- Allows to truncate files without read permission (previously:
EACCES
) - Allows to create a zero-filled file of specified length if it didn't exist at specified path
Creating file is not what pure truncate(2)
does, but it is done by truncate(1)
and kinda makes sense.
Alternatively, we can check for W_OK
and throw ENOENT
manually.