Skip to content

Commit

Permalink
Fix cp permissions when copying symlink contents, and add test.
Browse files Browse the repository at this point in the history
  • Loading branch information
landley committed Jan 12, 2019
1 parent bf76b49 commit c68fa66
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/cp.test
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ testing "-r dir1/* dir2" \
"cp -r one/* dir2 && diff -r one dir2 && echo yes" "yes\n" "" ""
rm -rf one dir dir2

touch walrus
chmod 644 walrus
ln -s walrus woot

testing "symlink dest permissions" "cp woot carpenter && stat -c %A carpenter" \
"-rw-r--r--\n" "" ""

# cp -r ../source destdir
# cp -r one/two/three missing
# cp -r one/two/three two
Expand Down
2 changes: 2 additions & 0 deletions toys/posix/cp.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ static int cp_node(struct dirtree *try)
catch = try->name;
break;
}
// When copying contents use symlink target's attributes
if (S_ISLNK(try->st.st_mode)) fstat(fdin, &try->st);
fdout = openat(cfd, catch, O_RDWR|O_CREAT|O_TRUNC, try->st.st_mode);
if (fdout >= 0) {
xsendfile(fdin, fdout);
Expand Down

0 comments on commit c68fa66

Please sign in to comment.