From 74aa48b78da835b72a5319b37bafb9e691755a75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8C=AB=E7=A7=91=E9=BE=99?= Date: Wed, 6 Jul 2022 14:37:18 +0000 Subject: [PATCH] cp: fix -D (--parents) (REWORK MINIMAL FIX) add: test for -D fix: b/c/d/FILE not copying into a/ with -D option dirname() is not needed when handling FLAG(D) since filename under src or dest should not be changed. github.com//issues/165 Signed-off-by: maokelong95 --- toys/posix/cp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/toys/posix/cp.c b/toys/posix/cp.c index bba5480..0608147 100644 --- a/toys/posix/cp.c +++ b/toys/posix/cp.c @@ -410,11 +410,10 @@ void cp_main(void) } if (destdir) { - char *s = FLAG(D) ? getdirname(src) : getbasename(src); + char *s = FLAG(D) ? src : getbasename(src); TT.destname = xmprintf("%s/%s", destname, s); if (FLAG(D)) { - free(s); if (!(s = fileunderdir(TT.destname, destname))) { error_msg("%s not under %s", TT.destname, destname); continue; -- Gitee