From 47a8842e78e790912ec0493a594b0eb1e972ab25 Mon Sep 17 00:00:00 2001 From: makepost Date: Mon, 10 Jun 2019 16:29:10 +0000 Subject: Fix cp -r dir/. symlink child. Remove the existing link before trying to re-create, passing the test. Add -p to the -r test as a regression guard, portage calls cp with both. --- toys/posix/cp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'toys/posix/cp.c') diff --git a/toys/posix/cp.c b/toys/posix/cp.c index e37b360d..681af025 100644 --- a/toys/posix/cp.c +++ b/toys/posix/cp.c @@ -252,7 +252,8 @@ static int cp_node(struct dirtree *try) // make symlink, or make block/char/fifo/socket if (S_ISLNK(try->st.st_mode) ? ((i = readlinkat0(tfd, try->name, toybuf, sizeof(toybuf))) && - !symlinkat(toybuf, cfd, catch)) + ((!unlinkat(cfd, catch, 0) || ENOENT == errno) && + !symlinkat(toybuf, cfd, catch))) : !mknodat(cfd, catch, try->st.st_mode, try->st.st_rdev)) { err = 0; -- cgit v1.2.3