aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJarno Mäkipää <jmakip87@gmail.com>2020-02-15 13:31:48 +0200
committerRob Landley <rob@landley.net>2020-03-08 13:56:54 -0500
commite76aeac3cc39b404ece0f4258ed378cd74379bcd (patch)
tree1d88c5619b4b72e691c37af130f6d8c67dd9ea50
parent2ec513e54cf34e86076bde871abf4f911844cef1 (diff)
downloadtoybox-e76aeac3cc39b404ece0f4258ed378cd74379bcd.tar.gz
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/landley/toybox/issues/165
-rwxr-xr-xtests/cp.test7
-rw-r--r--toys/posix/cp.c2
2 files changed, 8 insertions, 1 deletions
diff --git a/tests/cp.test b/tests/cp.test
index dfb80ea1..5c4a7474 100755
--- a/tests/cp.test
+++ b/tests/cp.test
@@ -120,6 +120,13 @@ testing "-T file" "cp -T b file && cat file" "b\n" "" ""
testing "-T dir" "cp -T b dir 2>/dev/null || echo expected" "expected\n" "" ""
rm b file
+mkdir -p b/c/d/
+mkdir a/
+echo a > b/c/d/file
+testing "-D b/c/d/file a/" "cp -D b/c/d/file a/ && cat a/b/c/d/file" "a\n" "" ""
+rm -rf a/
+rm -rf b/
+
# cp -r ../source destdir
# cp -r one/two/three missing
# cp -r one/two/three two
diff --git a/toys/posix/cp.c b/toys/posix/cp.c
index f70c0501..06f1ff92 100644
--- a/toys/posix/cp.c
+++ b/toys/posix/cp.c
@@ -407,7 +407,7 @@ void cp_main(void)
if (*--trail == '/') *trail = 0;
if (destdir) {
- char *s = FLAG(D) ? dirname(src) : getbasename(src);
+ char *s = FLAG(D) ? src : getbasename(src);
TT.destname = xmprintf("%s/%s", destname, s);
if (FLAG(D)) {