From 8e171638a472ca730513a45f6ca025f7699c1347 Mon Sep 17 00:00:00 2001 From: Tony Kelman Date: Thu, 16 Mar 2017 12:23:35 -0400 Subject: [PATCH] Fix #20925, cp not preserving permissions --- base/file.jl | 4 +++- test/file.jl | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/base/file.jl b/base/file.jl index 483afa2453473..c4f766a769aa6 100644 --- a/base/file.jl +++ b/base/file.jl @@ -726,7 +726,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)) @@ -738,6 +738,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 2996bd6650db4..6e29b120f12fe 100644 --- a/test/file.jl +++ b/test/file.jl @@ -81,8 +81,19 @@ if Sys.iswindows() 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