diff --git a/base/file.jl b/base/file.jl index 30eb9696de249..c663765bc25ee 100644 --- a/base/file.jl +++ b/base/file.jl @@ -515,7 +515,7 @@ function sendfile(src::AbstractString, dst::AbstractString) src_file = open(src, JL_O_RDONLY) src_open = true dst_file = open(dst, JL_O_CREAT | JL_O_TRUNC | JL_O_WRONLY, - S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP| S_IROTH | S_IWOTH) + S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) dst_open = true bytes = filesize(stat(src_file)) @@ -527,6 +527,8 @@ function sendfile(src::AbstractString, dst::AbstractString) if dst_open && isopen(dst_file) close(dst_file) end + # preserve permissions by default (issue #20925) + chmod(dst, filemode(src)) end end diff --git a/test/file.jl b/test/file.jl index ca1429605cd25..86df0d4ae92d2 100644 --- a/test/file.jl +++ b/test/file.jl @@ -80,8 +80,19 @@ if is_windows() else mktempdir() do tmpdir tmpfile=joinpath(tmpdir, "tempfile.txt") + tmpfile2=joinpath(tmpdir, "tempfile2.txt") touch(tmpfile) + cp(tmpfile, tmpfile2) + @test filemode(tmpfile) == filemode(tmpfile2) + rm(tmpfile2) + chmod(tmpfile, 0o777) + cp(tmpfile, tmpfile2) + @test filemode(tmpfile) == filemode(tmpfile2) + rm(tmpfile2) chmod(tmpfile, 0o707) + cp(tmpfile, tmpfile2) + @test filemode(tmpfile) == filemode(tmpfile2) + rm(tmpfile2) linkfile=joinpath(dir, "tempfile.txt") symlink(tmpfile, linkfile) permissions=0o776