From 3b9cfa70db019fa9b43ddba2d5620bff6c72bad6 Mon Sep 17 00:00:00 2001 From: Denys Nykula Date: Sat, 22 Jun 2019 14:57:59 +0300 Subject: Fix mv with trailing slash in source. Press tab, have bash complete dir name with a slash, notice musl rename() dislikes that. Replace trailing slash in the cp loop with a null character, if the command name is mv. Add the slash back if an error occurs. --- toys/posix/cp.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'toys/posix/cp.c') diff --git a/toys/posix/cp.c b/toys/posix/cp.c index 681af025..9989ed14 100644 --- a/toys/posix/cp.c +++ b/toys/posix/cp.c @@ -403,9 +403,14 @@ void cp_main(void) // Loop through sources for (i=0; iname[0] == 'm') { + while (*++trail); + if (*--trail == '/') *trail = 0; + } + if (destdir) { char *s = (toys.optflags&FLAG_D) ? getdirname(src) : getbasename(src); @@ -442,6 +447,7 @@ void cp_main(void) if (exists && no_clobber) rc = 0; } if (rc) rc = rename(src, TT.destname); + if (errno && !*trail) *trail = '/'; } // Copy if we didn't mv, skipping nonexistent sources -- cgit v1.2.3