Skip to content

Commit

Permalink
Mmap: fix grow! for non file IOs (#55849)
Browse files Browse the repository at this point in the history
Fixes #54203
Requires #55641

Based on
#55641 (comment)
cc. @JakeZw @ronisbr

---------

Co-authored-by: Jameson Nash <[email protected]>
(cherry picked from commit b0db75d)
  • Loading branch information
IanButterworth authored and KristofferC committed Sep 30, 2024
1 parent b4b9add commit 050ecea
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion 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(io) && return
if filelen < offset + len
failure = ccall(:jl_ftruncate, Cint, (Cint, Int64), fd(io), offset+len)
Base.systemerror(:ftruncate, failure != 0)
Expand Down Expand Up @@ -218,7 +220,7 @@ function mmap(io::IO,
# platform-specific mmapping
@static if Sys.isunix()
prot, flags, iswrite = settings(file_desc, shared)
if requestedSizeLarger
if requestedSizeLarger && isfile(io) # add a condition to this line to ensure it only checks files
if iswrite
if grow
grow!(io, offset, len)
Expand Down

0 comments on commit 050ecea

Please sign in to comment.