From 8e9d7aaa838ed58b7b354a3b378cda1bd84f8dc5 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 13 Mar 2021 03:13:21 -0600 Subject: Commit 3b9cfa70db needed some cleanup I forgot to do, oops. Elliott stumbled across one of the issues I forgot to fix. Added a couple comments and renamed a variable to try to clarify the code while I was there. --- toys/posix/cp.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'toys/posix') diff --git a/toys/posix/cp.c b/toys/posix/cp.c index 56fbadf9..d98c2ae7 100644 --- a/toys/posix/cp.c +++ b/toys/posix/cp.c @@ -412,11 +412,11 @@ void cp_main(void) // Loop through sources for (i=0; isrc && *trail=='/') *trail-- = 0; if (destdir) { char *s = FLAG(D) ? src : getbasename(src); @@ -433,6 +433,7 @@ void cp_main(void) } } else TT.destname = destname; + // "mv across devices" triggers cp fallback path, so set that as default errno = EXDEV; if (CFG_MV && toys.which->name[0] == 'm') { int force = FLAG(f), no_clobber = FLAG(n); @@ -446,18 +447,18 @@ void cp_main(void) // _else_) but I don't care. if (exists && (FLAG(i) || (!(st.st_mode & 0222) && isatty(0)))) { fprintf(stderr, "%s: overwrite '%s'", toys.which->name, TT.destname); - if (!yesno(0)) rc = 0; + if (!yesno(0)) send = 0; else unlink(TT.destname); } // if -n and dest exists, don't try to rename() or copy - if (exists && no_clobber) rc = 0; + if (exists && no_clobber) send = 0; } - if (rc) rc = rename(src, TT.destname); - if (errno && !*trail) *trail = '/'; + if (send) send = rename(src, TT.destname); + if (trail) trail[1] = '/'; } - // Copy if we didn't mv, skipping nonexistent sources - if (rc) { + // Copy if we didn't mv or hit an error, skipping nonexistent sources + if (send) { if (errno!=EXDEV || dirtree_flagread(src, DIRTREE_SHUTUP+ DIRTREE_SYMFOLLOW*!!(FLAG(H)||FLAG(L)), TT.callback)) perror_msg("bad '%s'", src); -- cgit v1.2.3