diff options
author | Eric Andersen <andersen@codepoet.org> | 2002-09-16 09:23:22 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2002-09-16 09:23:22 +0000 |
commit | 403a73a351d6275b095874cb28c7677d50aa10eb (patch) | |
tree | 2edffed2db6459f0843474c5ac4ea44ce6f99c0d | |
parent | 18b76e6f8047edf2e9e3d8fcc962a2e40ed8ffbd (diff) | |
download | busybox-w32-403a73a351d6275b095874cb28c7677d50aa10eb.tar.gz busybox-w32-403a73a351d6275b095874cb28c7677d50aa10eb.tar.bz2 busybox-w32-403a73a351d6275b095874cb28c7677d50aa10eb.zip |
Properly honor FILEUTILS_INTERACTIVE and FILEUTILS_FORCE for
file all file types (not just regular files and dirs). Unlink
destination files when needed.
-Erik
-rw-r--r-- | libbb/copy_file.c | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/libbb/copy_file.c b/libbb/copy_file.c index 3d174ddb3..1a584017f 100644 --- a/libbb/copy_file.c +++ b/libbb/copy_file.c | |||
@@ -203,17 +203,81 @@ int copy_file(const char *source, const char *dest, int flags) | |||
203 | } | 203 | } |
204 | } else if (S_ISBLK(source_stat.st_mode) || S_ISCHR(source_stat.st_mode) || | 204 | } else if (S_ISBLK(source_stat.st_mode) || S_ISCHR(source_stat.st_mode) || |
205 | S_ISSOCK(source_stat.st_mode)) { | 205 | S_ISSOCK(source_stat.st_mode)) { |
206 | |||
207 | if (dest_exists) { | ||
208 | if (flags & FILEUTILS_INTERACTIVE) { | ||
209 | fprintf(stderr, "%s: overwrite `%s'? ", applet_name, dest); | ||
210 | if (!ask_confirmation()) | ||
211 | return 0; | ||
212 | } | ||
213 | |||
214 | if (!(flags & FILEUTILS_FORCE)) { | ||
215 | perror_msg("unable to remove `%s'", dest); | ||
216 | return -1; | ||
217 | } | ||
218 | |||
219 | if (unlink(dest) < 0) { | ||
220 | perror_msg("unable to remove `%s'", dest); | ||
221 | return -1; | ||
222 | } | ||
223 | |||
224 | dest_exists = 0; | ||
225 | } | ||
226 | |||
206 | if (mknod(dest, source_stat.st_mode, source_stat.st_rdev) < 0) { | 227 | if (mknod(dest, source_stat.st_mode, source_stat.st_rdev) < 0) { |
207 | perror_msg("unable to create `%s'", dest); | 228 | perror_msg("unable to create `%s'", dest); |
208 | return -1; | 229 | return -1; |
209 | } | 230 | } |
210 | } else if (S_ISFIFO(source_stat.st_mode)) { | 231 | } else if (S_ISFIFO(source_stat.st_mode)) { |
232 | |||
233 | if (dest_exists) { | ||
234 | if (flags & FILEUTILS_INTERACTIVE) { | ||
235 | fprintf(stderr, "%s: overwrite `%s'? ", applet_name, dest); | ||
236 | if (!ask_confirmation()) | ||
237 | return 0; | ||
238 | } | ||
239 | |||
240 | if (!(flags & FILEUTILS_FORCE)) { | ||
241 | perror_msg("unable to remove `%s'", dest); | ||
242 | return -1; | ||
243 | } | ||
244 | |||
245 | if (unlink(dest) < 0) { | ||
246 | perror_msg("unable to remove `%s'", dest); | ||
247 | return -1; | ||
248 | } | ||
249 | |||
250 | dest_exists = 0; | ||
251 | } | ||
252 | |||
211 | if (mkfifo(dest, source_stat.st_mode) < 0) { | 253 | if (mkfifo(dest, source_stat.st_mode) < 0) { |
212 | perror_msg("cannot create fifo `%s'", dest); | 254 | perror_msg("cannot create fifo `%s'", dest); |
213 | return -1; | 255 | return -1; |
214 | } | 256 | } |
215 | } else if (S_ISLNK(source_stat.st_mode)) { | 257 | } else if (S_ISLNK(source_stat.st_mode)) { |
216 | char *lpath = xreadlink(source); | 258 | char *lpath; |
259 | |||
260 | if (dest_exists) { | ||
261 | if (flags & FILEUTILS_INTERACTIVE) { | ||
262 | fprintf(stderr, "%s: overwrite `%s'? ", applet_name, dest); | ||
263 | if (!ask_confirmation()) | ||
264 | return 0; | ||
265 | } | ||
266 | |||
267 | if (!(flags & FILEUTILS_FORCE)) { | ||
268 | perror_msg("unable to remove `%s'", dest); | ||
269 | return -1; | ||
270 | } | ||
271 | |||
272 | if (unlink(dest) < 0) { | ||
273 | perror_msg("unable to remove `%s'", dest); | ||
274 | return -1; | ||
275 | } | ||
276 | |||
277 | dest_exists = 0; | ||
278 | } | ||
279 | |||
280 | lpath = xreadlink(source); | ||
217 | if (symlink(lpath, dest) < 0) { | 281 | if (symlink(lpath, dest) < 0) { |
218 | perror_msg("cannot create symlink `%s'", dest); | 282 | perror_msg("cannot create symlink `%s'", dest); |
219 | return -1; | 283 | return -1; |