mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-10 23:15:02 +00:00
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:
committed by
narimiran
parent
d1016a3bc9
commit
f04fe4e4a3
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user