diff options
Diffstat (limited to 'coreutils/cp.c')
-rw-r--r-- | coreutils/cp.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/coreutils/cp.c b/coreutils/cp.c index 5b34c27e7..455bffbba 100644 --- a/coreutils/cp.c +++ b/coreutils/cp.c | |||
@@ -26,6 +26,7 @@ | |||
26 | //config: Also add support for --parents option. | 26 | //config: Also add support for --parents option. |
27 | 27 | ||
28 | //applet:IF_CP(APPLET_NOEXEC(cp, cp, BB_DIR_BIN, BB_SUID_DROP, cp)) | 28 | //applet:IF_CP(APPLET_NOEXEC(cp, cp, BB_DIR_BIN, BB_SUID_DROP, cp)) |
29 | /* NOEXEC despite cases when it can be a "runner" (cp -r LARGE_DIR NEW_DIR) */ | ||
29 | 30 | ||
30 | //kbuild:lib-$(CONFIG_CP) += cp.o | 31 | //kbuild:lib-$(CONFIG_CP) += cp.o |
31 | 32 | ||
@@ -47,6 +48,7 @@ | |||
47 | //usage: "\n -f Overwrite" | 48 | //usage: "\n -f Overwrite" |
48 | //usage: "\n -i Prompt before overwrite" | 49 | //usage: "\n -i Prompt before overwrite" |
49 | //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" | ||
50 | //usage: "\n -u Copy only newer files" | 52 | //usage: "\n -u Copy only newer files" |
51 | 53 | ||
52 | #include "libbb.h" | 54 | #include "libbb.h" |
@@ -92,13 +94,18 @@ int cp_main(int argc, char **argv) | |||
92 | "no-dereference\0" No_argument "P" | 94 | "no-dereference\0" No_argument "P" |
93 | "recursive\0" No_argument "R" | 95 | "recursive\0" No_argument "R" |
94 | "symbolic-link\0" No_argument "s" | 96 | "symbolic-link\0" No_argument "s" |
97 | "no-target-directory\0" No_argument "T" | ||
95 | "verbose\0" No_argument "v" | 98 | "verbose\0" No_argument "v" |
96 | "update\0" No_argument "u" | 99 | "update\0" No_argument "u" |
97 | "remove-destination\0" No_argument "\xff" | 100 | "remove-destination\0" No_argument "\xff" |
98 | "parents\0" No_argument "\xfe" | 101 | "parents\0" No_argument "\xfe" |
99 | ); | 102 | ); |
100 | #else | 103 | #else |
101 | flags = getopt32(argv, FILEUTILS_CP_OPTSTR); | 104 | flags = getopt32(argv, "^" |
105 | FILEUTILS_CP_OPTSTR | ||
106 | "\0" | ||
107 | "-2:l--s:s--l:Pd:rRd:Rd:apdR" | ||
108 | ); | ||
102 | #endif | 109 | #endif |
103 | /* Options of cp from GNU coreutils 6.10: | 110 | /* Options of cp from GNU coreutils 6.10: |
104 | * -a, --archive | 111 | * -a, --archive |
@@ -121,6 +128,8 @@ int cp_main(int argc, char **argv) | |||
121 | * remove each existing destination file before attempting to open | 128 | * remove each existing destination file before attempting to open |
122 | * --parents | 129 | * --parents |
123 | * use full source file name under DIRECTORY | 130 | * use full source file name under DIRECTORY |
131 | * -T, --no-target-directory | ||
132 | * treat DEST as a normal file | ||
124 | * NOT SUPPORTED IN BBOX: | 133 | * NOT SUPPORTED IN BBOX: |
125 | * --backup[=CONTROL] | 134 | * --backup[=CONTROL] |
126 | * make a backup of each existing destination file | 135 | * make a backup of each existing destination file |
@@ -139,8 +148,6 @@ int cp_main(int argc, char **argv) | |||
139 | * override the usual backup suffix | 148 | * override the usual backup suffix |
140 | * -t, --target-directory=DIRECTORY | 149 | * -t, --target-directory=DIRECTORY |
141 | * copy all SOURCE arguments into DIRECTORY | 150 | * copy all SOURCE arguments into DIRECTORY |
142 | * -T, --no-target-directory | ||
143 | * treat DEST as a normal file | ||
144 | * -x, --one-file-system | 151 | * -x, --one-file-system |
145 | * stay on this file system | 152 | * stay on this file system |
146 | * -Z, --context=CONTEXT | 153 | * -Z, --context=CONTEXT |
@@ -175,6 +182,12 @@ int cp_main(int argc, char **argv) | |||
175 | if (d_flags < 0) | 182 | if (d_flags < 0) |
176 | return EXIT_FAILURE; | 183 | return EXIT_FAILURE; |
177 | 184 | ||
185 | if (flags & FILEUTILS_NO_TARGET_DIR) { /* -T */ | ||
186 | if (!(s_flags & 2) && (d_flags & 2)) | ||
187 | /* cp -T NOTDIR DIR */ | ||
188 | bb_error_msg_and_die("'%s' is a directory", last); | ||
189 | } | ||
190 | |||
178 | #if ENABLE_FEATURE_CP_LONG_OPTIONS | 191 | #if ENABLE_FEATURE_CP_LONG_OPTIONS |
179 | //bb_error_msg("flags:%x FILEUTILS_RMDEST:%x OPT_parents:%x", | 192 | //bb_error_msg("flags:%x FILEUTILS_RMDEST:%x OPT_parents:%x", |
180 | // flags, FILEUTILS_RMDEST, OPT_parents); | 193 | // flags, FILEUTILS_RMDEST, OPT_parents); |
@@ -192,11 +205,14 @@ int cp_main(int argc, char **argv) | |||
192 | if (!((s_flags | d_flags) & 2) | 205 | if (!((s_flags | d_flags) & 2) |
193 | /* ...or: recursing, the 1st is a directory, and the 2nd doesn't exist... */ | 206 | /* ...or: recursing, the 1st is a directory, and the 2nd doesn't exist... */ |
194 | || ((flags & FILEUTILS_RECUR) && (s_flags & 2) && !d_flags) | 207 | || ((flags & FILEUTILS_RECUR) && (s_flags & 2) && !d_flags) |
208 | || (flags & FILEUTILS_NO_TARGET_DIR) | ||
195 | ) { | 209 | ) { |
196 | /* Do a simple copy */ | 210 | /* Do a simple copy */ |
197 | dest = last; | 211 | dest = last; |
198 | goto DO_COPY; /* NB: argc==2 -> *++argv==last */ | 212 | goto DO_COPY; /* NB: argc==2 -> *++argv==last */ |
199 | } | 213 | } |
214 | } else if (flags & FILEUTILS_NO_TARGET_DIR) { | ||
215 | bb_error_msg_and_die("too many arguments"); | ||
200 | } | 216 | } |
201 | 217 | ||
202 | while (1) { | 218 | while (1) { |