diff options
author | Aaro Koskinen <aaro.koskinen@iki.fi> | 2018-02-01 09:29:05 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-02-01 09:30:59 +0100 |
commit | d15d7a0a4b07a55268546f0d32b6a3ed78a2ac77 (patch) | |
tree | c1657aff3ed6cc999f1090930dac9671926b36a8 /coreutils | |
parent | d6f0f03b68fc4cf9ffb8006e192e36f0ebf51ea6 (diff) | |
download | busybox-w32-d15d7a0a4b07a55268546f0d32b6a3ed78a2ac77.tar.gz busybox-w32-d15d7a0a4b07a55268546f0d32b6a3ed78a2ac77.tar.bz2 busybox-w32-d15d7a0a4b07a55268546f0d32b6a3ed78a2ac77.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>
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/cp.c | 15 |
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 @@ | |||
48 | //usage: "\n -f Overwrite" | 48 | //usage: "\n -f Overwrite" |
49 | //usage: "\n -i Prompt before overwrite" | 49 | //usage: "\n -i Prompt before overwrite" |
50 | //usage: "\n -l,-s Create (sym)links" | 50 | //usage: "\n -l,-s Create (sym)links" |
51 | //usage: "\n -T Treat DEST as a normal file" | ||
51 | //usage: "\n -u Copy only newer files" | 52 | //usage: "\n -u Copy only newer files" |
52 | 53 | ||
53 | #include "libbb.h" | 54 | #include "libbb.h" |
@@ -93,6 +94,7 @@ int cp_main(int argc, char **argv) | |||
93 | "no-dereference\0" No_argument "P" | 94 | "no-dereference\0" No_argument "P" |
94 | "recursive\0" No_argument "R" | 95 | "recursive\0" No_argument "R" |
95 | "symbolic-link\0" No_argument "s" | 96 | "symbolic-link\0" No_argument "s" |
97 | "no-target-directory\0" No_argument "T" | ||
96 | "verbose\0" No_argument "v" | 98 | "verbose\0" No_argument "v" |
97 | "update\0" No_argument "u" | 99 | "update\0" No_argument "u" |
98 | "remove-destination\0" No_argument "\xff" | 100 | "remove-destination\0" No_argument "\xff" |
@@ -122,6 +124,8 @@ int cp_main(int argc, char **argv) | |||
122 | * remove each existing destination file before attempting to open | 124 | * remove each existing destination file before attempting to open |
123 | * --parents | 125 | * --parents |
124 | * use full source file name under DIRECTORY | 126 | * use full source file name under DIRECTORY |
127 | * -T, --no-target-directory | ||
128 | * treat DEST as a normal file | ||
125 | * NOT SUPPORTED IN BBOX: | 129 | * NOT SUPPORTED IN BBOX: |
126 | * --backup[=CONTROL] | 130 | * --backup[=CONTROL] |
127 | * make a backup of each existing destination file | 131 | * make a backup of each existing destination file |
@@ -140,8 +144,6 @@ int cp_main(int argc, char **argv) | |||
140 | * override the usual backup suffix | 144 | * override the usual backup suffix |
141 | * -t, --target-directory=DIRECTORY | 145 | * -t, --target-directory=DIRECTORY |
142 | * copy all SOURCE arguments into DIRECTORY | 146 | * copy all SOURCE arguments into DIRECTORY |
143 | * -T, --no-target-directory | ||
144 | * treat DEST as a normal file | ||
145 | * -x, --one-file-system | 147 | * -x, --one-file-system |
146 | * stay on this file system | 148 | * stay on this file system |
147 | * -Z, --context=CONTEXT | 149 | * -Z, --context=CONTEXT |
@@ -176,6 +178,12 @@ int cp_main(int argc, char **argv) | |||
176 | if (d_flags < 0) | 178 | if (d_flags < 0) |
177 | return EXIT_FAILURE; | 179 | return EXIT_FAILURE; |
178 | 180 | ||
181 | if (flags & FILEUTILS_NO_TARGET_DIR) { /* -T */ | ||
182 | if (!(s_flags & 2) && (d_flags & 2)) | ||
183 | /* cp -T NOTDIR DIR */ | ||
184 | bb_error_msg_and_die("'%s' is a directory", last); | ||
185 | } | ||
186 | |||
179 | #if ENABLE_FEATURE_CP_LONG_OPTIONS | 187 | #if ENABLE_FEATURE_CP_LONG_OPTIONS |
180 | //bb_error_msg("flags:%x FILEUTILS_RMDEST:%x OPT_parents:%x", | 188 | //bb_error_msg("flags:%x FILEUTILS_RMDEST:%x OPT_parents:%x", |
181 | // flags, FILEUTILS_RMDEST, OPT_parents); | 189 | // flags, FILEUTILS_RMDEST, OPT_parents); |
@@ -193,11 +201,14 @@ int cp_main(int argc, char **argv) | |||
193 | if (!((s_flags | d_flags) & 2) | 201 | if (!((s_flags | d_flags) & 2) |
194 | /* ...or: recursing, the 1st is a directory, and the 2nd doesn't exist... */ | 202 | /* ...or: recursing, the 1st is a directory, and the 2nd doesn't exist... */ |
195 | || ((flags & FILEUTILS_RECUR) && (s_flags & 2) && !d_flags) | 203 | || ((flags & FILEUTILS_RECUR) && (s_flags & 2) && !d_flags) |
204 | || (flags & FILEUTILS_NO_TARGET_DIR) | ||
196 | ) { | 205 | ) { |
197 | /* Do a simple copy */ | 206 | /* Do a simple copy */ |
198 | dest = last; | 207 | dest = last; |
199 | goto DO_COPY; /* NB: argc==2 -> *++argv==last */ | 208 | goto DO_COPY; /* NB: argc==2 -> *++argv==last */ |
200 | } | 209 | } |
210 | } else if (flags & FILEUTILS_NO_TARGET_DIR) { | ||
211 | bb_error_msg_and_die("too many arguments"); | ||
201 | } | 212 | } |
202 | 213 | ||
203 | while (1) { | 214 | while (1) { |