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-403a73a351d6275b095874cb28c7677d50aa10eb.tar.gz |
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) } } else if (S_ISBLK(source_stat.st_mode) || S_ISCHR(source_stat.st_mode) || S_ISSOCK(source_stat.st_mode)) { + + if (dest_exists) { + if (flags & FILEUTILS_INTERACTIVE) { + fprintf(stderr, "%s: overwrite `%s'? ", applet_name, dest); + if (!ask_confirmation()) + return 0; + } + + if (!(flags & FILEUTILS_FORCE)) { + perror_msg("unable to remove `%s'", dest); + return -1; + } + + if (unlink(dest) < 0) { + perror_msg("unable to remove `%s'", dest); + return -1; + } + + dest_exists = 0; + } + if (mknod(dest, source_stat.st_mode, source_stat.st_rdev) < 0) { perror_msg("unable to create `%s'", dest); return -1; } } else if (S_ISFIFO(source_stat.st_mode)) { + + if (dest_exists) { + if (flags & FILEUTILS_INTERACTIVE) { + fprintf(stderr, "%s: overwrite `%s'? ", applet_name, dest); + if (!ask_confirmation()) + return 0; + } + + if (!(flags & FILEUTILS_FORCE)) { + perror_msg("unable to remove `%s'", dest); + return -1; + } + + if (unlink(dest) < 0) { + perror_msg("unable to remove `%s'", dest); + return -1; + } + + dest_exists = 0; + } + if (mkfifo(dest, source_stat.st_mode) < 0) { perror_msg("cannot create fifo `%s'", dest); return -1; } } else if (S_ISLNK(source_stat.st_mode)) { - char *lpath = xreadlink(source); + char *lpath; + + if (dest_exists) { + if (flags & FILEUTILS_INTERACTIVE) { + fprintf(stderr, "%s: overwrite `%s'? ", applet_name, dest); + if (!ask_confirmation()) + return 0; + } + + if (!(flags & FILEUTILS_FORCE)) { + perror_msg("unable to remove `%s'", dest); + return -1; + } + + if (unlink(dest) < 0) { + perror_msg("unable to remove `%s'", dest); + return -1; + } + + dest_exists = 0; + } + + lpath = xreadlink(source); if (symlink(lpath, dest) < 0) { perror_msg("cannot create symlink `%s'", dest); return -1; |