memfiles.nim resizeFile fallback logic bug (#25408)

`e` is not cleared when falling back to `ftruncate`

(cherry picked from commit 4b615aca46)
This commit is contained in:
Ryan McConnell
2026-01-03 12:08:12 -05:00
committed by narimiran
parent d1016a3bc9
commit f04fe4e4a3

View File

@@ -57,8 +57,12 @@ proc setFileSize(fh: FileHandle, newFileSize = -1, oldSize = -1): OSErrorCode =
when declared(posix_fallocate):
while (e = posix_fallocate(fh, 0, newFileSize); e == EINTR):
discard
if (e == EINVAL or e == EOPNOTSUPP) and ftruncate(fh, newFileSize) == -1:
result = osLastError() # fallback arguable; Most portable BUT allows SEGV
if e == EINVAL or e == EOPNOTSUPP or e == ENOSYS:
# fallback arguable; Most portable BUT allows SEGV
if ftruncate(fh, newFileSize) == -1:
result = osLastError()
else:
discard
elif e != 0:
result = osLastError()
else: # shrink the file