Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 3 | * Mini copy_file implementation for busybox |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 4 | * |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 5 | * Copyright (C) 2001 by Matt Kraai <kraai@alumni.carnegiemellon.edu> |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 6 | * |
Rob Landley | 2f30932 | 2005-11-01 21:55:14 +0000 | [diff] [blame^] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 8 | * |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 11 | #include <sys/types.h> |
| 12 | #include <sys/stat.h> |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 13 | #include <unistd.h> |
| 14 | #include <fcntl.h> |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 15 | #include <utime.h> |
| 16 | #include <errno.h> |
| 17 | #include <dirent.h> |
| 18 | #include <stdlib.h> |
Manuel Novoa III | a2949aa | 2001-06-29 18:59:32 +0000 | [diff] [blame] | 19 | #include <string.h> |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 20 | |
Matt Kraai | ace02dc | 2001-12-17 15:26:36 +0000 | [diff] [blame] | 21 | #include "busybox.h" |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 22 | |
Rob Landley | 2f30932 | 2005-11-01 21:55:14 +0000 | [diff] [blame^] | 23 | /* Compiler version-specific crap that should be in a header file somewhere. */ |
| 24 | |
| 25 | #if !((__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)) |
| 26 | #define lchown chown |
| 27 | #endif |
| 28 | |
| 29 | |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 30 | int copy_file(const char *source, const char *dest, int flags) |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 31 | { |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 32 | struct stat source_stat; |
| 33 | struct stat dest_stat; |
Eric Andersen | a9a220b | 2002-09-17 08:42:21 +0000 | [diff] [blame] | 34 | int dest_exists = 0; |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 35 | int status = 0; |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 36 | |
Matt Kraai | 4c557bf | 2001-10-05 01:35:10 +0000 | [diff] [blame] | 37 | if ((!(flags & FILEUTILS_DEREFERENCE) && |
Matt Kraai | 0144103 | 2001-04-24 01:30:02 +0000 | [diff] [blame] | 38 | lstat(source, &source_stat) < 0) || |
Matt Kraai | 4c557bf | 2001-10-05 01:35:10 +0000 | [diff] [blame] | 39 | ((flags & FILEUTILS_DEREFERENCE) && |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 40 | stat(source, &source_stat) < 0)) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 41 | bb_perror_msg("%s", source); |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 42 | return -1; |
Glenn L McGrath | 4949faf | 2001-04-11 16:23:35 +0000 | [diff] [blame] | 43 | } |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 44 | |
Eric Andersen | 02b8dfc | 2002-09-16 10:23:38 +0000 | [diff] [blame] | 45 | if (lstat(dest, &dest_stat) < 0) { |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 46 | if (errno != ENOENT) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 47 | bb_perror_msg("unable to stat `%s'", dest); |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 48 | return -1; |
Glenn L McGrath | 4949faf | 2001-04-11 16:23:35 +0000 | [diff] [blame] | 49 | } |
Eric Andersen | a9a220b | 2002-09-17 08:42:21 +0000 | [diff] [blame] | 50 | } else { |
| 51 | if (source_stat.st_dev == dest_stat.st_dev && |
Mike Frysinger | 2ed05ab | 2005-04-14 02:52:50 +0000 | [diff] [blame] | 52 | source_stat.st_ino == dest_stat.st_ino) |
| 53 | { |
| 54 | bb_error_msg("`%s' and `%s' are the same file", source, dest); |
| 55 | return -1; |
| 56 | } |
Eric Andersen | a9a220b | 2002-09-17 08:42:21 +0000 | [diff] [blame] | 57 | dest_exists = 1; |
| 58 | } |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 59 | |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 60 | if (S_ISDIR(source_stat.st_mode)) { |
| 61 | DIR *dp; |
| 62 | struct dirent *d; |
Matt Kraai | 218aa37 | 2001-04-30 17:32:43 +0000 | [diff] [blame] | 63 | mode_t saved_umask = 0; |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 64 | |
Matt Kraai | 0144103 | 2001-04-24 01:30:02 +0000 | [diff] [blame] | 65 | if (!(flags & FILEUTILS_RECUR)) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 66 | bb_error_msg("%s: omitting directory", source); |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 67 | return -1; |
Glenn L McGrath | 4949faf | 2001-04-11 16:23:35 +0000 | [diff] [blame] | 68 | } |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 69 | |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 70 | /* Create DEST. */ |
| 71 | if (dest_exists) { |
| 72 | if (!S_ISDIR(dest_stat.st_mode)) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 73 | bb_error_msg("`%s' is not a directory", dest); |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 74 | return -1; |
Glenn L McGrath | 4949faf | 2001-04-11 16:23:35 +0000 | [diff] [blame] | 75 | } |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 76 | } else { |
Matt Kraai | 218aa37 | 2001-04-30 17:32:43 +0000 | [diff] [blame] | 77 | mode_t mode; |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 78 | saved_umask = umask(0); |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 79 | |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 80 | mode = source_stat.st_mode; |
Matt Kraai | 0144103 | 2001-04-24 01:30:02 +0000 | [diff] [blame] | 81 | if (!(flags & FILEUTILS_PRESERVE_STATUS)) |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 82 | mode = source_stat.st_mode & ~saved_umask; |
| 83 | mode |= S_IRWXU; |
| 84 | |
| 85 | if (mkdir(dest, mode) < 0) { |
| 86 | umask(saved_umask); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 87 | bb_perror_msg("cannot create directory `%s'", dest); |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 88 | return -1; |
Glenn L McGrath | 4949faf | 2001-04-11 16:23:35 +0000 | [diff] [blame] | 89 | } |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 90 | |
| 91 | umask(saved_umask); |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 92 | } |
Matt Kraai | bf0a010 | 2001-06-11 13:58:02 +0000 | [diff] [blame] | 93 | |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 94 | /* Recursively copy files in SOURCE. */ |
| 95 | if ((dp = opendir(source)) == NULL) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 96 | bb_perror_msg("unable to open directory `%s'", source); |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 97 | status = -1; |
Rob Landley | 2f30932 | 2005-11-01 21:55:14 +0000 | [diff] [blame^] | 98 | goto preserve_status; |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | while ((d = readdir(dp)) != NULL) { |
| 102 | char *new_source, *new_dest; |
| 103 | |
Glenn L McGrath | 393183d | 2003-05-26 14:07:50 +0000 | [diff] [blame] | 104 | new_source = concat_subpath_file(source, d->d_name); |
| 105 | if(new_source == NULL) |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 106 | continue; |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 107 | new_dest = concat_path_file(dest, d->d_name); |
| 108 | if (copy_file(new_source, new_dest, flags) < 0) |
| 109 | status = -1; |
| 110 | free(new_source); |
| 111 | free(new_dest); |
| 112 | } |
Eric Andersen | a9a220b | 2002-09-17 08:42:21 +0000 | [diff] [blame] | 113 | /* closedir have only EBADF error, but "dp" not changes */ |
| 114 | closedir(dp); |
Matt Kraai | 218aa37 | 2001-04-30 17:32:43 +0000 | [diff] [blame] | 115 | |
| 116 | if (!dest_exists && |
| 117 | chmod(dest, source_stat.st_mode & ~saved_umask) < 0) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 118 | bb_perror_msg("unable to change permissions of `%s'", dest); |
Matt Kraai | 218aa37 | 2001-04-30 17:32:43 +0000 | [diff] [blame] | 119 | status = -1; |
| 120 | } |
Rob Landley | 2f30932 | 2005-11-01 21:55:14 +0000 | [diff] [blame^] | 121 | } else if (S_ISREG(source_stat.st_mode) || (flags & FILEUTILS_DEREFERENCE)) |
| 122 | { |
Glenn L McGrath | f62ea20 | 2003-12-20 04:38:01 +0000 | [diff] [blame] | 123 | int src_fd; |
| 124 | int dst_fd; |
Matt Kraai | ace02dc | 2001-12-17 15:26:36 +0000 | [diff] [blame] | 125 | #ifdef CONFIG_FEATURE_PRESERVE_HARDLINKS |
| 126 | char *link_name; |
| 127 | |
| 128 | if (!(flags & FILEUTILS_DEREFERENCE) && |
| 129 | is_in_ino_dev_hashtable(&source_stat, &link_name)) { |
| 130 | if (link(link_name, dest) < 0) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 131 | bb_perror_msg("unable to link `%s'", dest); |
Matt Kraai | ace02dc | 2001-12-17 15:26:36 +0000 | [diff] [blame] | 132 | return -1; |
| 133 | } |
| 134 | |
| 135 | return 0; |
| 136 | } |
Rob Landley | 2f30932 | 2005-11-01 21:55:14 +0000 | [diff] [blame^] | 137 | add_to_ino_dev_hashtable(&source_stat, dest); |
Matt Kraai | ace02dc | 2001-12-17 15:26:36 +0000 | [diff] [blame] | 138 | #endif |
Glenn L McGrath | f62ea20 | 2003-12-20 04:38:01 +0000 | [diff] [blame] | 139 | src_fd = open(source, O_RDONLY); |
| 140 | if (src_fd == -1) { |
| 141 | bb_perror_msg("unable to open `%s'", source); |
| 142 | return(-1); |
Matt Kraai | 14b7c5d | 2001-12-11 16:43:48 +0000 | [diff] [blame] | 143 | } |
| 144 | |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 145 | if (dest_exists) { |
Matt Kraai | 0144103 | 2001-04-24 01:30:02 +0000 | [diff] [blame] | 146 | if (flags & FILEUTILS_INTERACTIVE) { |
Paul Fox | c337d29 | 2005-07-19 21:31:05 +0000 | [diff] [blame] | 147 | fprintf(stderr, "%s: overwrite `%s'? ", bb_applet_name, dest); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 148 | if (!bb_ask_confirmation()) { |
Glenn L McGrath | f62ea20 | 2003-12-20 04:38:01 +0000 | [diff] [blame] | 149 | close (src_fd); |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 150 | return 0; |
Matt Kraai | 14b7c5d | 2001-12-11 16:43:48 +0000 | [diff] [blame] | 151 | } |
Glenn L McGrath | 4949faf | 2001-04-11 16:23:35 +0000 | [diff] [blame] | 152 | } |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 153 | |
Glenn L McGrath | 447bc2d | 2004-01-11 05:20:59 +0000 | [diff] [blame] | 154 | dst_fd = open(dest, O_WRONLY|O_TRUNC); |
Glenn L McGrath | f62ea20 | 2003-12-20 04:38:01 +0000 | [diff] [blame] | 155 | if (dst_fd == -1) { |
Matt Kraai | 0144103 | 2001-04-24 01:30:02 +0000 | [diff] [blame] | 156 | if (!(flags & FILEUTILS_FORCE)) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 157 | bb_perror_msg("unable to open `%s'", dest); |
Glenn L McGrath | f62ea20 | 2003-12-20 04:38:01 +0000 | [diff] [blame] | 158 | close(src_fd); |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 159 | return -1; |
| 160 | } |
| 161 | |
| 162 | if (unlink(dest) < 0) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 163 | bb_perror_msg("unable to remove `%s'", dest); |
Glenn L McGrath | f62ea20 | 2003-12-20 04:38:01 +0000 | [diff] [blame] | 164 | close(src_fd); |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 165 | return -1; |
| 166 | } |
| 167 | |
| 168 | dest_exists = 0; |
| 169 | } |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 170 | } |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 171 | |
| 172 | if (!dest_exists) { |
Glenn L McGrath | f62ea20 | 2003-12-20 04:38:01 +0000 | [diff] [blame] | 173 | dst_fd = open(dest, O_WRONLY|O_CREAT, source_stat.st_mode); |
| 174 | if (dst_fd == -1) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 175 | bb_perror_msg("unable to open `%s'", dest); |
Glenn L McGrath | f62ea20 | 2003-12-20 04:38:01 +0000 | [diff] [blame] | 176 | close(src_fd); |
| 177 | return(-1); |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 178 | } |
| 179 | } |
| 180 | |
Glenn L McGrath | f62ea20 | 2003-12-20 04:38:01 +0000 | [diff] [blame] | 181 | if (bb_copyfd_eof(src_fd, dst_fd) == -1) |
Matt Kraai | bf0a010 | 2001-06-11 13:58:02 +0000 | [diff] [blame] | 182 | status = -1; |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 183 | |
Glenn L McGrath | f62ea20 | 2003-12-20 04:38:01 +0000 | [diff] [blame] | 184 | if (close(dst_fd) < 0) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 185 | bb_perror_msg("unable to close `%s'", dest); |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 186 | status = -1; |
| 187 | } |
| 188 | |
Glenn L McGrath | f62ea20 | 2003-12-20 04:38:01 +0000 | [diff] [blame] | 189 | if (close(src_fd) < 0) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 190 | bb_perror_msg("unable to close `%s'", source); |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 191 | status = -1; |
| 192 | } |
Rob Landley | 2f30932 | 2005-11-01 21:55:14 +0000 | [diff] [blame^] | 193 | } else if (S_ISBLK(source_stat.st_mode) || S_ISCHR(source_stat.st_mode) || |
Eric Andersen | a9a220b | 2002-09-17 08:42:21 +0000 | [diff] [blame] | 194 | S_ISSOCK(source_stat.st_mode) || S_ISFIFO(source_stat.st_mode) || |
| 195 | S_ISLNK(source_stat.st_mode)) { |
Eric Andersen | 403a73a | 2002-09-16 09:23:22 +0000 | [diff] [blame] | 196 | |
Paul Fox | 0a92bbf | 2005-07-19 20:47:33 +0000 | [diff] [blame] | 197 | if (dest_exists) { |
| 198 | if((flags & FILEUTILS_FORCE) == 0) { |
| 199 | fprintf(stderr, "`%s' exists\n", dest); |
| 200 | return -1; |
| 201 | } |
| 202 | if(unlink(dest) < 0) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 203 | bb_perror_msg("unable to remove `%s'", dest); |
Eric Andersen | 403a73a | 2002-09-16 09:23:22 +0000 | [diff] [blame] | 204 | return -1; |
Eric Andersen | 403a73a | 2002-09-16 09:23:22 +0000 | [diff] [blame] | 205 | } |
Paul Fox | 0a92bbf | 2005-07-19 20:47:33 +0000 | [diff] [blame] | 206 | } |
Rob Landley | 2f30932 | 2005-11-01 21:55:14 +0000 | [diff] [blame^] | 207 | if (S_ISFIFO(source_stat.st_mode)) { |
| 208 | if (mkfifo(dest, source_stat.st_mode) < 0) { |
| 209 | bb_perror_msg("cannot create fifo `%s'", dest); |
| 210 | return -1; |
| 211 | } |
| 212 | } else if (S_ISLNK(source_stat.st_mode)) { |
| 213 | char *lpath; |
| 214 | |
| 215 | lpath = xreadlink(source); |
| 216 | if (symlink(lpath, dest) < 0) { |
| 217 | bb_perror_msg("cannot create symlink `%s'", dest); |
| 218 | return -1; |
| 219 | } |
| 220 | free(lpath); |
| 221 | |
| 222 | if (flags & FILEUTILS_PRESERVE_STATUS) |
| 223 | if (lchown(dest, source_stat.st_uid, source_stat.st_gid) < 0) |
| 224 | bb_perror_msg("unable to preserve ownership of `%s'", dest); |
| 225 | |
| 226 | return 0; |
| 227 | |
| 228 | } else { |
| 229 | if (mknod(dest, source_stat.st_mode, source_stat.st_rdev) < 0) { |
| 230 | bb_perror_msg("unable to create `%s'", dest); |
| 231 | return -1; |
| 232 | } |
| 233 | } |
Eric Andersen | a9a220b | 2002-09-17 08:42:21 +0000 | [diff] [blame] | 234 | } else { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 235 | bb_error_msg("internal error: unrecognized file type"); |
Eric Andersen | a9a220b | 2002-09-17 08:42:21 +0000 | [diff] [blame] | 236 | return -1; |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Rob Landley | 2f30932 | 2005-11-01 21:55:14 +0000 | [diff] [blame^] | 239 | preserve_status: |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 240 | |
Matt Kraai | 0144103 | 2001-04-24 01:30:02 +0000 | [diff] [blame] | 241 | if (flags & FILEUTILS_PRESERVE_STATUS) { |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 242 | struct utimbuf times; |
Rob Landley | 2f30932 | 2005-11-01 21:55:14 +0000 | [diff] [blame^] | 243 | char *msg="unable to preserve %s of `%s'"; |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 244 | |
| 245 | times.actime = source_stat.st_atime; |
| 246 | times.modtime = source_stat.st_mtime; |
| 247 | if (utime(dest, ×) < 0) |
Rob Landley | 2f30932 | 2005-11-01 21:55:14 +0000 | [diff] [blame^] | 248 | bb_perror_msg(msg, "times", dest); |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 249 | if (chown(dest, source_stat.st_uid, source_stat.st_gid) < 0) { |
| 250 | source_stat.st_mode &= ~(S_ISUID | S_ISGID); |
Rob Landley | 2f30932 | 2005-11-01 21:55:14 +0000 | [diff] [blame^] | 251 | bb_perror_msg(msg, "ownership", dest); |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 252 | } |
| 253 | if (chmod(dest, source_stat.st_mode) < 0) |
Rob Landley | 2f30932 | 2005-11-01 21:55:14 +0000 | [diff] [blame^] | 254 | bb_perror_msg(msg, "permissions", dest); |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 255 | } |
| 256 | |
Matt Kraai | 24abecc | 2001-04-30 16:37:04 +0000 | [diff] [blame] | 257 | return status; |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 258 | } |