aboutsummaryrefslogtreecommitdiff
path: root/coreutils
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-01 09:30:59 +0100
commitd15d7a0a4b07a55268546f0d32b6a3ed78a2ac77 (patch)
treec1657aff3ed6cc999f1090930dac9671926b36a8 /coreutils
parentd6f0f03b68fc4cf9ffb8006e192e36f0ebf51ea6 (diff)
downloadbusybox-d15d7a0a4b07a55268546f0d32b6a3ed78a2ac77.tar.gz
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>
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/cp.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/coreutils/cp.c b/coreutils/cp.c
index 05c725cd0..8d93c6fe4 100644
--- a/coreutils/cp.c
+++ b/coreutils/cp.c
@@ -48,6 +48,7 @@
//usage: "\n -f Overwrite"
//usage: "\n -i Prompt before overwrite"
//usage: "\n -l,-s Create (sym)links"
+//usage: "\n -T Treat DEST as a normal file"
//usage: "\n -u Copy only newer files"
#include "libbb.h"
@@ -93,6 +94,7 @@ int cp_main(int argc, char **argv)
"no-dereference\0" No_argument "P"
"recursive\0" No_argument "R"
"symbolic-link\0" No_argument "s"
+ "no-target-directory\0" No_argument "T"
"verbose\0" No_argument "v"
"update\0" No_argument "u"
"remove-destination\0" No_argument "\xff"
@@ -122,6 +124,8 @@ int cp_main(int argc, char **argv)
* remove each existing destination file before attempting to open
* --parents
* use full source file name under DIRECTORY
+ * -T, --no-target-directory
+ * treat DEST as a normal file
* NOT SUPPORTED IN BBOX:
* --backup[=CONTROL]
* make a backup of each existing destination file
@@ -140,8 +144,6 @@ int cp_main(int argc, char **argv)
* override the usual backup suffix
* -t, --target-directory=DIRECTORY
* copy all SOURCE arguments into DIRECTORY
- * -T, --no-target-directory
- * treat DEST as a normal file
* -x, --one-file-system
* stay on this file system
* -Z, --context=CONTEXT
@@ -176,6 +178,12 @@ int cp_main(int argc, char **argv)
if (d_flags < 0)
return EXIT_FAILURE;
+ if (flags & FILEUTILS_NO_TARGET_DIR) { /* -T */
+ if (!(s_flags & 2) && (d_flags & 2))
+ /* cp -T NOTDIR DIR */
+ bb_error_msg_and_die("'%s' is a directory", last);
+ }
+
#if ENABLE_FEATURE_CP_LONG_OPTIONS
//bb_error_msg("flags:%x FILEUTILS_RMDEST:%x OPT_parents:%x",
// flags, FILEUTILS_RMDEST, OPT_parents);
@@ -193,11 +201,14 @@ int cp_main(int argc, char **argv)
if (!((s_flags | d_flags) & 2)
/* ...or: recursing, the 1st is a directory, and the 2nd doesn't exist... */
|| ((flags & FILEUTILS_RECUR) && (s_flags & 2) && !d_flags)
+ || (flags & FILEUTILS_NO_TARGET_DIR)
) {
/* Do a simple copy */
dest = last;
goto DO_COPY; /* NB: argc==2 -> *++argv==last */
}
+ } else if (flags & FILEUTILS_NO_TARGET_DIR) {
+ bb_error_msg_and_die("too many arguments");
}
while (1) {