aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2021-06-22 15:28:34 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2021-06-22 15:28:34 +0200
commit56bbbfae7df48f778362d1848d2a4afd2c293d76 (patch)
treeb0ad2dff6ec225e2f41383f870f2f55d47911dd8
parent91b9549a8c739e5f0061dffb292d0dedbe913892 (diff)
downloadbusybox-w32-56bbbfae7df48f778362d1848d2a4afd2c293d76.tar.gz
busybox-w32-56bbbfae7df48f778362d1848d2a4afd2c293d76.tar.bz2
busybox-w32-56bbbfae7df48f778362d1848d2a4afd2c293d76.zip
cp: implement -n
function old new delta .rodata 103681 103722 +41 packed_usage 33698 33717 +19 copy_file 1678 1696 +18 cp_main 500 492 -8 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/1 up/down: 78/-8) Total: 70 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--coreutils/cp.c19
-rw-r--r--include/libbb.h29
-rw-r--r--libbb/copy_file.c2
3 files changed, 28 insertions, 22 deletions
diff --git a/coreutils/cp.c b/coreutils/cp.c
index 8b9e03c95..b7f0e290f 100644
--- a/coreutils/cp.c
+++ b/coreutils/cp.c
@@ -84,8 +84,8 @@
84// (SELinux) set SELinux security context of copy to CONTEXT 84// (SELinux) set SELinux security context of copy to CONTEXT
85 85
86//usage:#define cp_trivial_usage 86//usage:#define cp_trivial_usage
87//usage: "[-arPLHpfilsTu] SOURCE DEST\n" 87//usage: "[-arPLHpfinlsTu] SOURCE DEST\n"
88//usage: "or: cp [-arPLHpfilsu] SOURCE... { -t DIRECTORY | DIRECTORY }" 88//usage: "or: cp [-arPLHpfinlsu] SOURCE... { -t DIRECTORY | DIRECTORY }"
89//usage:#define cp_full_usage "\n\n" 89//usage:#define cp_full_usage "\n\n"
90//usage: "Copy SOURCEs to DEST\n" 90//usage: "Copy SOURCEs to DEST\n"
91//usage: "\n -a Same as -dpR" 91//usage: "\n -a Same as -dpR"
@@ -99,6 +99,7 @@
99//usage: "\n -p Preserve file attributes if possible" 99//usage: "\n -p Preserve file attributes if possible"
100//usage: "\n -f Overwrite" 100//usage: "\n -f Overwrite"
101//usage: "\n -i Prompt before overwrite" 101//usage: "\n -i Prompt before overwrite"
102//usage: "\n -n Don't overwrite"
102//usage: "\n -l,-s Create (sym)links" 103//usage: "\n -l,-s Create (sym)links"
103//usage: "\n -T Refuse to copy if DEST is a directory" 104//usage: "\n -T Refuse to copy if DEST is a directory"
104//usage: "\n -t DIR Copy all SOURCEs into DIR" 105//usage: "\n -t DIR Copy all SOURCEs into DIR"
@@ -122,9 +123,9 @@ int cp_main(int argc, char **argv)
122 int status; 123 int status;
123 enum { 124 enum {
124#if ENABLE_FEATURE_CP_LONG_OPTIONS 125#if ENABLE_FEATURE_CP_LONG_OPTIONS
125 /*OPT_rmdest = FILEUTILS_RMDEST = 1 << FILEUTILS_CP_OPTNUM */ 126 /*OPT_rmdest = FILEUTILS_RMDEST = 1 << FILEUTILS_CP_OPTBITS */
126 OPT_parents = 1 << (FILEUTILS_CP_OPTNUM+1), 127 OPT_parents = 1 << (FILEUTILS_CP_OPTBITS+1),
127 OPT_reflink = 1 << (FILEUTILS_CP_OPTNUM+2), 128 OPT_reflink = 1 << (FILEUTILS_CP_OPTBITS+2),
128#endif 129#endif
129 }; 130 };
130#if ENABLE_FEATURE_CP_LONG_OPTIONS 131#if ENABLE_FEATURE_CP_LONG_OPTIONS
@@ -134,23 +135,25 @@ int cp_main(int argc, char **argv)
134 flags = getopt32long(argv, "^" 135 flags = getopt32long(argv, "^"
135 FILEUTILS_CP_OPTSTR 136 FILEUTILS_CP_OPTSTR
136 "\0" 137 "\0"
137 // Need at least two arguments 138 // Need at least one argument. (Usually two+, but -t DIR can have only one)
138 // Soft- and hardlinking doesn't mix 139 // Soft- and hardlinking doesn't mix
139 // -P and -d are the same (-P is POSIX, -d is GNU) 140 // -P and -d are the same (-P is POSIX, -d is GNU)
140 // -r and -R are the same 141 // -r and -R are the same
141 // -R (and therefore -r) turns on -d (coreutils does this) 142 // -R (and therefore -r) turns on -d (coreutils does this)
142 // -a = -pdR 143 // -a = -pdR
143 /* At least one argument. (Usually two+, but -t DIR can have only one) */ 144 // -i overrides -n and vice versa (last wins)
144 "-1:l--s:s--l:Pd:rRd:Rd:apdR", 145 "-1:l--s:s--l:Pd:rRd:Rd:apdR:i-n:n-i",
145 "archive\0" No_argument "a" 146 "archive\0" No_argument "a"
146 "force\0" No_argument "f" 147 "force\0" No_argument "f"
147 "interactive\0" No_argument "i" 148 "interactive\0" No_argument "i"
149 "no-clobber\0" No_argument "n"
148 "link\0" No_argument "l" 150 "link\0" No_argument "l"
149 "dereference\0" No_argument "L" 151 "dereference\0" No_argument "L"
150 "no-dereference\0" No_argument "P" 152 "no-dereference\0" No_argument "P"
151 "recursive\0" No_argument "R" 153 "recursive\0" No_argument "R"
152 "symbolic-link\0" No_argument "s" 154 "symbolic-link\0" No_argument "s"
153 "no-target-directory\0" No_argument "T" 155 "no-target-directory\0" No_argument "T"
156 "target-directory\0" Required_argument "t"
154 "verbose\0" No_argument "v" 157 "verbose\0" No_argument "v"
155 "update\0" No_argument "u" 158 "update\0" No_argument "u"
156 "remove-destination\0" No_argument "\xff" 159 "remove-destination\0" No_argument "\xff"
diff --git a/include/libbb.h b/include/libbb.h
index e38e97ac2..251d7231c 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -450,28 +450,29 @@ enum { /* cp.c, mv.c, install.c depend on these values. CAREFUL when changing th
450 FILEUTILS_RECUR = 1 << 2, /* -R */ 450 FILEUTILS_RECUR = 1 << 2, /* -R */
451 FILEUTILS_FORCE = 1 << 3, /* -f */ 451 FILEUTILS_FORCE = 1 << 3, /* -f */
452 FILEUTILS_INTERACTIVE = 1 << 4, /* -i */ 452 FILEUTILS_INTERACTIVE = 1 << 4, /* -i */
453 FILEUTILS_MAKE_HARDLINK = 1 << 5, /* -l */ 453 FILEUTILS_NO_OVERWRITE = 1 << 5, /* -n */
454 FILEUTILS_MAKE_SOFTLINK = 1 << 6, /* -s */ 454 FILEUTILS_MAKE_HARDLINK = 1 << 6, /* -l */
455 FILEUTILS_DEREF_SOFTLINK = 1 << 7, /* -L */ 455 FILEUTILS_MAKE_SOFTLINK = 1 << 7, /* -s */
456 FILEUTILS_DEREFERENCE_L0 = 1 << 8, /* -H */ 456 FILEUTILS_DEREF_SOFTLINK = 1 << 8, /* -L */
457 FILEUTILS_DEREFERENCE_L0 = 1 << 9, /* -H */
457 /* -a = -pdR (mapped in cp.c) */ 458 /* -a = -pdR (mapped in cp.c) */
458 /* -r = -dR (mapped in cp.c) */ 459 /* -r = -dR (mapped in cp.c) */
459 /* -P = -d (mapped in cp.c) */ 460 /* -P = -d (mapped in cp.c) */
460 FILEUTILS_VERBOSE = (1 << 12) * ENABLE_FEATURE_VERBOSE, /* -v */ 461 FILEUTILS_VERBOSE = (1 << 13) * ENABLE_FEATURE_VERBOSE, /* -v */
461 FILEUTILS_UPDATE = 1 << 13, /* -u */ 462 FILEUTILS_UPDATE = 1 << 14, /* -u */
462 FILEUTILS_NO_TARGET_DIR = 1 << 14, /* -T */ 463 FILEUTILS_NO_TARGET_DIR = 1 << 15, /* -T */
463 FILEUTILS_TARGET_DIR = 1 << 15, /* -t DIR */ 464 FILEUTILS_TARGET_DIR = 1 << 16, /* -t DIR */
464#if ENABLE_SELINUX 465#if ENABLE_SELINUX
465 FILEUTILS_PRESERVE_SECURITY_CONTEXT = 1 << 16, /* -c */ 466 FILEUTILS_PRESERVE_SECURITY_CONTEXT = 1 << 17, /* -c */
466#endif 467#endif
467#define FILEUTILS_CP_OPTSTR "pdRfilsLHarPvuTt:" IF_SELINUX("c") 468#define FILEUTILS_CP_OPTSTR "pdRfinlsLHarPvuTt:" IF_SELINUX("c")
468/* How many bits in FILEUTILS_CP_OPTSTR? */ 469/* How many bits in FILEUTILS_CP_OPTSTR? */
469 FILEUTILS_CP_OPTNUM = 17 - !ENABLE_SELINUX, 470 FILEUTILS_CP_OPTBITS = 18 - !ENABLE_SELINUX,
470 471
471 FILEUTILS_RMDEST = 1 << (17 - !ENABLE_SELINUX), /* --remove-destination */ 472 FILEUTILS_RMDEST = 1 << (19 - !ENABLE_SELINUX), /* cp --remove-destination */
472 /* bit 18 skipped for "cp --parents" */ 473 /* bit 18 skipped for "cp --parents" */
473 FILEUTILS_REFLINK = 1 << (19 - !ENABLE_SELINUX), /* cp --reflink=auto */ 474 FILEUTILS_REFLINK = 1 << (20 - !ENABLE_SELINUX), /* cp --reflink=auto */
474 FILEUTILS_REFLINK_ALWAYS = 1 << (20 - !ENABLE_SELINUX), /* cp --reflink[=always] */ 475 FILEUTILS_REFLINK_ALWAYS = 1 << (21 - !ENABLE_SELINUX), /* cp --reflink[=always] */
475 /* 476 /*
476 * Hole. cp may have some bits set here, 477 * Hole. cp may have some bits set here,
477 * they should not affect remove_file()/copy_file() 478 * they should not affect remove_file()/copy_file()
diff --git a/libbb/copy_file.c b/libbb/copy_file.c
index 49d1ec9c6..044bc3c20 100644
--- a/libbb/copy_file.c
+++ b/libbb/copy_file.c
@@ -111,6 +111,8 @@ int FAST_FUNC copy_file(const char *source, const char *dest, int flags)
111 bb_error_msg("'%s' and '%s' are the same file", source, dest); 111 bb_error_msg("'%s' and '%s' are the same file", source, dest);
112 return -1; 112 return -1;
113 } 113 }
114 if (flags & FILEUTILS_NO_OVERWRITE) /* cp -n */
115 return 0;
114 dest_exists = 1; 116 dest_exists = 1;
115 } 117 }
116 118