Skip to content

Commit dcf8f65

Browse files
IanButterworthvtjnash
authored andcommitted
Mmap: fix grow! for non file IOs (#55849)
Fixes #54203 Requires #55641 Based on #55641 (comment) cc. @JakeZw @ronisbr --------- Co-authored-by: Jameson Nash <[email protected]> (cherry picked from commit b0db75d)
1 parent d2e5c8f commit dcf8f65

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

stdlib/Mmap/src/Mmap.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ grow!(::Anonymous,o::Integer,l::Integer) = return
8686
function grow!(io::IO, offset::Integer, len::Integer)
8787
pos = position(io)
8888
filelen = filesize(io)
89+
# If non-regular file skip trying to grow since we know that will fail the ftruncate syscall
90+
filelen == 0 && !isfile(io) && return
8991
if filelen < offset + len
9092
failure = ccall(:jl_ftruncate, Cint, (Cint, Int64), fd(io), offset+len)
9193
Base.systemerror(:ftruncate, failure != 0)
@@ -218,7 +220,7 @@ function mmap(io::IO,
218220
# platform-specific mmapping
219221
@static if Sys.isunix()
220222
prot, flags, iswrite = settings(file_desc, shared)
221-
if requestedSizeLarger
223+
if requestedSizeLarger && isfile(io) # add a condition to this line to ensure it only checks files
222224
if iswrite
223225
if grow
224226
grow!(io, offset, len)

0 commit comments

Comments
 (0)