Skip to content

Commit 75d982d

Browse files
authored
Don't require write permissions in readdlm (#19337)
1 parent 32a1b8c commit 75d982d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

base/datafmt.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ function readdlm_auto(input::AbstractString, dlm::Char, T::Type, eol::Char, auto
115115
use_mmap = get(optsd, :use_mmap, is_windows() ? false : true)
116116
fsz = filesize(input)
117117
if use_mmap && fsz > 0 && fsz < typemax(Int)
118-
a = Mmap.mmap(input, Vector{UInt8}, (Int(fsz),))
118+
a = open(input, "r") do f
119+
Mmap.mmap(f, Vector{UInt8}, (Int(fsz),))
120+
end
119121
# TODO: It would be nicer to use String(a) without making a copy,
120122
# but because the mmap'ed array is not NUL-terminated this causes
121123
# jl_try_substrtod to segfault below.

test/datafmt.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,13 @@ for writefunc in ((io,x) -> show(io, "text/csv", x),
262262
@test vec(readcsv(io)) == x
263263
end
264264
end
265+
266+
# Test that we can read a write protected file
267+
let fn = tempname()
268+
open(fn, "w") do f
269+
write(f, "Julia")
270+
end
271+
chmod(fn, 0o444)
272+
readdlm(fn)[] == "Julia"
273+
rm(fn)
274+
end

0 commit comments

Comments
 (0)