aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaro Koskinen <aaro.koskinen@iki.fi>2018-02-01 09:29:05 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-02-14 17:38:29 +0100
commitce5ba9277b5b712c18208f8116edc2dcfa490e43 (patch)
treee280b12dd6172c0a10a9ad69217dd023bc272788
parent20f02c3c871cf0c8d9d2f2dad11d96c0ea41e0df (diff)
downloadbusybox-w32-ce5ba9277b5b712c18208f8116edc2dcfa490e43.tar.gz
busybox-w32-ce5ba9277b5b712c18208f8116edc2dcfa490e43.tar.bz2
busybox-w32-ce5ba9277b5b712c18208f8116edc2dcfa490e43.zip
cp: implement -T
Implement "cp -T". Some Linux kernel Makefiles started using this recently, so allow also building on systems using busybox cp. function old new delta cp_main 360 428 +68 copy_file 1678 1676 -2 packed_usage 32290 32259 -31 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 76/-39) Total: 35 bytes Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--coreutils/cp.c15
-rw-r--r--include/libbb.h7
2 files changed, 17 insertions, 5 deletions
diff --git a/coreutils/cp.c b/coreutils/cp.c
index 5b34c27e7..a76af7b7c 100644
--- a/coreutils/cp.c
+++ b/coreutils/cp.c
@@ -47,6 +47,7 @@
47//usage: "\n -f Overwrite" 47//usage: "\n -f Overwrite"
48//usage: "\n -i Prompt before overwrite" 48//usage: "\n -i Prompt before overwrite"
49//usage: "\n -l,-s Create (sym)links" 49//usage: "\n -l,-s Create (sym)links"
50//usage: "\n -T Treat DEST as a normal file"
50//usage: "\n -u Copy only newer files" 51//usage: "\n -u Copy only newer files"
51 52
52#include "libbb.h" 53#include "libbb.h"
@@ -92,6 +93,7 @@ int cp_main(int argc, char **argv)
92 "no-dereference\0" No_argument "P" 93 "no-dereference\0" No_argument "P"
93 "recursive\0" No_argument "R" 94 "recursive\0" No_argument "R"
94 "symbolic-link\0" No_argument "s" 95 "symbolic-link\0" No_argument "s"
96 "no-target-directory\0" No_argument "T"
95 "verbose\0" No_argument "v" 97 "verbose\0" No_argument "v"
96 "update\0" No_argument "u" 98 "update\0" No_argument "u"
97 "remove-destination\0" No_argument "\xff" 99 "remove-destination\0" No_argument "\xff"
@@ -121,6 +123,8 @@ int cp_main(int argc, char **argv)
121 * remove each existing destination file before attempting to open 123 * remove each existing destination file before attempting to open
122 * --parents 124 * --parents
123 * use full source file name under DIRECTORY 125 * use full source file name under DIRECTORY
126 * -T, --no-target-directory
127 * treat DEST as a normal file
124 * NOT SUPPORTED IN BBOX: 128 * NOT SUPPORTED IN BBOX:
125 * --backup[=CONTROL] 129 * --backup[=CONTROL]
126 * make a backup of each existing destination file 130 * make a backup of each existing destination file
@@ -139,8 +143,6 @@ int cp_main(int argc, char **argv)
139 * override the usual backup suffix 143 * override the usual backup suffix
140 * -t, --target-directory=DIRECTORY 144 * -t, --target-directory=DIRECTORY
141 * copy all SOURCE arguments into DIRECTORY 145 * copy all SOURCE arguments into DIRECTORY
142 * -T, --no-target-directory
143 * treat DEST as a normal file
144 * -x, --one-file-system 146 * -x, --one-file-system
145 * stay on this file system 147 * stay on this file system
146 * -Z, --context=CONTEXT 148 * -Z, --context=CONTEXT
@@ -175,6 +177,12 @@ int cp_main(int argc, char **argv)
175 if (d_flags < 0) 177 if (d_flags < 0)
176 return EXIT_FAILURE; 178 return EXIT_FAILURE;
177 179
180 if (flags & FILEUTILS_NO_TARGET_DIR) { /* -T */
181 if (!(s_flags & 2) && (d_flags & 2))
182 /* cp -T NOTDIR DIR */
183 bb_error_msg_and_die("'%s' is a directory", last);
184 }
185
178#if ENABLE_FEATURE_CP_LONG_OPTIONS 186#if ENABLE_FEATURE_CP_LONG_OPTIONS
179 //bb_error_msg("flags:%x FILEUTILS_RMDEST:%x OPT_parents:%x", 187 //bb_error_msg("flags:%x FILEUTILS_RMDEST:%x OPT_parents:%x",
180 // flags, FILEUTILS_RMDEST, OPT_parents); 188 // flags, FILEUTILS_RMDEST, OPT_parents);
@@ -192,11 +200,14 @@ int cp_main(int argc, char **argv)
192 if (!((s_flags | d_flags) & 2) 200 if (!((s_flags | d_flags) & 2)
193 /* ...or: recursing, the 1st is a directory, and the 2nd doesn't exist... */ 201 /* ...or: recursing, the 1st is a directory, and the 2nd doesn't exist... */
194 || ((flags & FILEUTILS_RECUR) && (s_flags & 2) && !d_flags) 202 || ((flags & FILEUTILS_RECUR) && (s_flags & 2) && !d_flags)
203 || (flags & FILEUTILS_NO_TARGET_DIR)
195 ) { 204 ) {
196 /* Do a simple copy */ 205 /* Do a simple copy */
197 dest = last; 206 dest = last;
198 goto DO_COPY; /* NB: argc==2 -> *++argv==last */ 207 goto DO_COPY; /* NB: argc==2 -> *++argv==last */
199 } 208 }
209 } else if (flags & FILEUTILS_NO_TARGET_DIR) {
210 bb_error_msg_and_die("too many arguments");
200 } 211 }
201 212
202 while (1) { 213 while (1) {
diff --git a/include/libbb.h b/include/libbb.h
index daccf154a..1dbec3d0f 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -404,10 +404,11 @@ enum { /* cp.c, mv.c, install.c depend on these values. CAREFUL when changing th
404 /* -P = -d (mapped in cp.c) */ 404 /* -P = -d (mapped in cp.c) */
405 FILEUTILS_VERBOSE = (1 << 12) * ENABLE_FEATURE_VERBOSE, /* -v */ 405 FILEUTILS_VERBOSE = (1 << 12) * ENABLE_FEATURE_VERBOSE, /* -v */
406 FILEUTILS_UPDATE = 1 << 13, /* -u */ 406 FILEUTILS_UPDATE = 1 << 13, /* -u */
407 FILEUTILS_NO_TARGET_DIR = 1 << 14, /* -T */
407#if ENABLE_SELINUX 408#if ENABLE_SELINUX
408 FILEUTILS_PRESERVE_SECURITY_CONTEXT = 1 << 14, /* -c */ 409 FILEUTILS_PRESERVE_SECURITY_CONTEXT = 1 << 15, /* -c */
409#endif 410#endif
410 FILEUTILS_RMDEST = 1 << (15 - !ENABLE_SELINUX), /* --remove-destination */ 411 FILEUTILS_RMDEST = 1 << (16 - !ENABLE_SELINUX), /* --remove-destination */
411 /* 412 /*
412 * Hole. cp may have some bits set here, 413 * Hole. cp may have some bits set here,
413 * they should not affect remove_file()/copy_file() 414 * they should not affect remove_file()/copy_file()
@@ -417,7 +418,7 @@ enum { /* cp.c, mv.c, install.c depend on these values. CAREFUL when changing th
417#endif 418#endif
418 FILEUTILS_IGNORE_CHMOD_ERR = 1 << 31, 419 FILEUTILS_IGNORE_CHMOD_ERR = 1 << 31,
419}; 420};
420#define FILEUTILS_CP_OPTSTR "pdRfilsLHarPvu" IF_SELINUX("c") 421#define FILEUTILS_CP_OPTSTR "pdRfilsLHarPvuT" IF_SELINUX("c")
421extern int remove_file(const char *path, int flags) FAST_FUNC; 422extern int remove_file(const char *path, int flags) FAST_FUNC;
422/* NB: without FILEUTILS_RECUR in flags, it will basically "cat" 423/* NB: without FILEUTILS_RECUR in flags, it will basically "cat"
423 * the source, not copy (unless "source" is a directory). 424 * the source, not copy (unless "source" is a directory).