Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fall back to slower stat filesize if optimized filesize fails #55641

Merged
4 changes: 2 additions & 2 deletions base/iostream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ end
function filesize(s::IOStream)
sz = @_lock_ios s ccall(:ios_filesize, Int64, (Ptr{Cvoid},), s.ios)
if sz == -1
err = Libc.errno()
throw(IOError(string("filesize: ", Libc.strerror(err), " for ", s.name), err))
# if `s` is not seekable `ios_filesize` can fail, so fall back to slower stat method
sz = filesize(stat(s))
end
return sz
end
Expand Down
2 changes: 2 additions & 0 deletions stdlib/Mmap/src/Mmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ grow!(::Anonymous,o::Integer,l::Integer) = return
function grow!(io::IO, offset::Integer, len::Integer)
pos = position(io)
filelen = filesize(io)
# If non-regular file skip trying to grow since we know that will fail the ftruncate syscall
filelen == 0 && isfile(stat(io)) && return
oscardssmith marked this conversation as resolved.
Show resolved Hide resolved
if filelen < offset + len
failure = ccall(:jl_ftruncate, Cint, (Cint, Int64), fd(io), offset+len)
Base.systemerror(:ftruncate, failure != 0)
Expand Down
Loading