Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #20925, cp not preserving permissions #21055

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like in other cases we've been making this a mode::Unsigned = 0o666 kw-arg, which also seems good

dst_open = true

bytes = filesize(stat(src_file))
Expand All @@ -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

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