Skip to content

Commit

Permalink
Fix JuliaLang#20925, cp not preserving permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
tkelman authored and staticfloat committed Jun 2, 2018
1 parent 5583ae4 commit 8e17163
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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

Expand Down
11 changes: 11 additions & 0 deletions test/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8e17163

Please sign in to comment.