changeset 785:50441fee583d

Teach cp to do -n.
author Rob Landley <rob@landley.net>
date Thu, 10 Jan 2013 20:19:23 -0600
parents d8b2f7706f82
children 5bc258a4c750
files toys/posix/cp.c
diffstat 1 files changed, 8 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/toys/posix/cp.c	Wed Jan 09 05:16:48 2013 -0600
+++ b/toys/posix/cp.c	Thu Jan 10 20:19:23 2013 -0600
@@ -4,7 +4,7 @@
  *
  * TODO: sHLP
 
-USE_CP(NEWTOY(cp, "<2"USE_CP_MORE("rdavsl")"RHLPfip", TOYFLAG_BIN))
+USE_CP(NEWTOY(cp, "<2"USE_CP_MORE("rdavsln")"RHLPfip[-ni]", TOYFLAG_BIN))
 
 config CP
   bool "cp"
@@ -30,10 +30,11 @@
   help
     usage: cp [-rdavsl]
 
+    -a	same as -dpr
+    -d	don't dereference symlinks
+    -l	hard link instead of copy
+    -n	no clobber (don't overwrite DEST)
     -r	synonym for -R
-    -d	don't dereference symlinks
-    -a	same as -dpr
-    -l	hard link instead of copy
     -s	symlink instead of copy
     -v	verbose
 */
@@ -84,10 +85,10 @@
     return 0;
   }
 
-  // Handle -i and -v
+  // Handle -inv
 
-  if ((flags & FLAG_i) && !faccessat(cfd, catch, R_OK, 0)
-    && !yesno("cp: overwrite", 1)) return 0;
+  if ((flags & (FLAG_i|FLAG_n)) && !faccessat(cfd, catch, R_OK, 0))
+    if ((flags & FLAG_n) || !yesno("cp: overwrite", 1)) return 0;
 
   if (flags & FLAG_v) {
     char *s = dirtree_path(try, 0);