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
8 changes: 7 additions & 1 deletion base/iostream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,13 @@ function position(s::IOStream)
end

function filesize(s::IOStream)
sz = @_lock_ios s ccall(:ios_filesize, Int64, (Ptr{Cvoid},), s.ios)
sz = try
@_lock_ios s ccall(:ios_filesize, Int64, (Ptr{Cvoid},), s.ios)
catch e
e isa IOError || rethrow()
# if `s` is not seekable `ios_filesize` can fail, so fall back to slower stat method
filesize(stat(s))
end
if sz == -1
err = Libc.errno()
throw(IOError(string("filesize: ", Libc.strerror(err), " for ", s.name), err))
IanButterworth marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Loading