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 | |
Rob Landley | c983274 | 2006-06-24 21:27:36 +0000 | [diff] [blame] | 11 | #include "libbb.h" |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 12 | |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 13 | static int retry_overwrite(const char *dest, int flags) |
| 14 | { |
| 15 | if (!(flags & (FILEUTILS_FORCE|FILEUTILS_INTERACTIVE))) { |
| 16 | fprintf(stderr, "'%s' exists\n", dest); |
| 17 | return -1; |
| 18 | } |
| 19 | if (flags & FILEUTILS_INTERACTIVE) { |
| 20 | fprintf(stderr, "%s: overwrite '%s'? ", applet_name, dest); |
| 21 | if (!bb_ask_confirmation()) |
| 22 | return 0; // not allowed to overwrite |
| 23 | } |
| 24 | if (unlink(dest) < 0) { |
| 25 | bb_perror_msg("cannot remove '%s'", dest); |
| 26 | return -1; // error |
| 27 | } |
| 28 | return 1; // ok (to try again) |
| 29 | } |
| 30 | |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 31 | int copy_file(const char *source, const char *dest, int flags) |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 32 | { |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 33 | struct stat source_stat; |
| 34 | struct stat dest_stat; |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 35 | int status = 0; |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 36 | signed char dest_exists = 0; |
| 37 | signed char ovr; |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 38 | |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 39 | #define FLAGS_DEREF (flags & FILEUTILS_DEREFERENCE) |
| 40 | |
| 41 | if ((FLAGS_DEREF ? stat : lstat)(source, &source_stat) < 0) { |
| 42 | // This may be a dangling symlink. |
| 43 | // Making [sym]links to dangling symlinks works, so... |
| 44 | if (flags & (FILEUTILS_MAKE_SOFTLINK|FILEUTILS_MAKE_HARDLINK)) |
| 45 | goto make_links; |
| 46 | bb_perror_msg("cannot stat '%s'", source); |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 47 | return -1; |
Glenn L McGrath | 4949faf | 2001-04-11 16:23:35 +0000 | [diff] [blame] | 48 | } |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 49 | |
Eric Andersen | 02b8dfc | 2002-09-16 10:23:38 +0000 | [diff] [blame] | 50 | if (lstat(dest, &dest_stat) < 0) { |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 51 | if (errno != ENOENT) { |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 52 | bb_perror_msg("cannot stat '%s'", dest); |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 53 | return -1; |
Glenn L McGrath | 4949faf | 2001-04-11 16:23:35 +0000 | [diff] [blame] | 54 | } |
Eric Andersen | a9a220b | 2002-09-17 08:42:21 +0000 | [diff] [blame] | 55 | } else { |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 56 | if (source_stat.st_dev == dest_stat.st_dev |
| 57 | && source_stat.st_ino == dest_stat.st_ino |
| 58 | ) { |
| 59 | bb_error_msg("'%s' and '%s' are the same file", source, dest); |
Mike Frysinger | 2ed05ab | 2005-04-14 02:52:50 +0000 | [diff] [blame] | 60 | return -1; |
| 61 | } |
Eric Andersen | a9a220b | 2002-09-17 08:42:21 +0000 | [diff] [blame] | 62 | dest_exists = 1; |
| 63 | } |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 64 | |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 65 | if (S_ISDIR(source_stat.st_mode)) { |
| 66 | DIR *dp; |
| 67 | struct dirent *d; |
Matt Kraai | 218aa37 | 2001-04-30 17:32:43 +0000 | [diff] [blame] | 68 | mode_t saved_umask = 0; |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 69 | |
Matt Kraai | 0144103 | 2001-04-24 01:30:02 +0000 | [diff] [blame] | 70 | if (!(flags & FILEUTILS_RECUR)) { |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 71 | bb_error_msg("omitting directory '%s'", source); |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 72 | return -1; |
Glenn L McGrath | 4949faf | 2001-04-11 16:23:35 +0000 | [diff] [blame] | 73 | } |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 74 | |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 75 | /* Create DEST. */ |
| 76 | if (dest_exists) { |
| 77 | if (!S_ISDIR(dest_stat.st_mode)) { |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 78 | bb_error_msg("target '%s' is not a directory", dest); |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 79 | return -1; |
Glenn L McGrath | 4949faf | 2001-04-11 16:23:35 +0000 | [diff] [blame] | 80 | } |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 81 | } else { |
Matt Kraai | 218aa37 | 2001-04-30 17:32:43 +0000 | [diff] [blame] | 82 | mode_t mode; |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 83 | saved_umask = umask(0); |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 84 | |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 85 | mode = source_stat.st_mode; |
Matt Kraai | 0144103 | 2001-04-24 01:30:02 +0000 | [diff] [blame] | 86 | if (!(flags & FILEUTILS_PRESERVE_STATUS)) |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 87 | mode = source_stat.st_mode & ~saved_umask; |
| 88 | mode |= S_IRWXU; |
| 89 | |
| 90 | if (mkdir(dest, mode) < 0) { |
| 91 | umask(saved_umask); |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 92 | bb_perror_msg("cannot create directory '%s'", dest); |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 93 | return -1; |
Glenn L McGrath | 4949faf | 2001-04-11 16:23:35 +0000 | [diff] [blame] | 94 | } |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 95 | |
| 96 | umask(saved_umask); |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 97 | } |
Matt Kraai | bf0a010 | 2001-06-11 13:58:02 +0000 | [diff] [blame] | 98 | |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 99 | /* Recursively copy files in SOURCE. */ |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 100 | dp = opendir(source); |
| 101 | if (dp == NULL) { |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 102 | status = -1; |
Rob Landley | 2f30932 | 2005-11-01 21:55:14 +0000 | [diff] [blame] | 103 | goto preserve_status; |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | while ((d = readdir(dp)) != NULL) { |
| 107 | char *new_source, *new_dest; |
| 108 | |
Glenn L McGrath | 393183d | 2003-05-26 14:07:50 +0000 | [diff] [blame] | 109 | new_source = concat_subpath_file(source, d->d_name); |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 110 | if (new_source == NULL) |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 111 | continue; |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 112 | new_dest = concat_path_file(dest, d->d_name); |
| 113 | if (copy_file(new_source, new_dest, flags) < 0) |
| 114 | status = -1; |
| 115 | free(new_source); |
| 116 | free(new_dest); |
| 117 | } |
Eric Andersen | a9a220b | 2002-09-17 08:42:21 +0000 | [diff] [blame] | 118 | closedir(dp); |
Matt Kraai | 218aa37 | 2001-04-30 17:32:43 +0000 | [diff] [blame] | 119 | |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 120 | if (!dest_exists |
| 121 | && chmod(dest, source_stat.st_mode & ~saved_umask) < 0 |
| 122 | ) { |
| 123 | bb_perror_msg("cannot change permissions of '%s'", dest); |
Matt Kraai | 218aa37 | 2001-04-30 17:32:43 +0000 | [diff] [blame] | 124 | status = -1; |
| 125 | } |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 126 | |
| 127 | } else if (flags & (FILEUTILS_MAKE_SOFTLINK|FILEUTILS_MAKE_HARDLINK)) { |
| 128 | int (*lf)(const char *oldpath, const char *newpath); |
| 129 | make_links: |
| 130 | // Hmm... maybe |
| 131 | // if (DEREF && MAKE_SOFTLINK) source = realpath(source) ? |
| 132 | // (but realpath returns NULL on dangling symlinks...) |
| 133 | lf = (flags & FILEUTILS_MAKE_SOFTLINK) ? symlink : link; |
| 134 | if (lf(source, dest) < 0) { |
| 135 | ovr = retry_overwrite(dest, flags); |
| 136 | if (ovr <= 0) |
| 137 | return ovr; |
| 138 | if (lf(source, dest) < 0) { |
| 139 | bb_perror_msg("cannot create link '%s'", dest); |
| 140 | return -1; |
| 141 | } |
| 142 | } |
| 143 | return 0; |
| 144 | |
| 145 | } else if (S_ISREG(source_stat.st_mode) |
| 146 | // Huh? DEREF uses stat, which never returns links IIRC... |
| 147 | || (FLAGS_DEREF && S_ISLNK(source_stat.st_mode)) |
| 148 | ) { |
Glenn L McGrath | f62ea20 | 2003-12-20 04:38:01 +0000 | [diff] [blame] | 149 | int src_fd; |
| 150 | int dst_fd; |
Rob Landley | c983274 | 2006-06-24 21:27:36 +0000 | [diff] [blame] | 151 | if (ENABLE_FEATURE_PRESERVE_HARDLINKS) { |
| 152 | char *link_name; |
Matt Kraai | ace02dc | 2001-12-17 15:26:36 +0000 | [diff] [blame] | 153 | |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 154 | if (!FLAGS_DEREF |
| 155 | && is_in_ino_dev_hashtable(&source_stat, &link_name) |
| 156 | ) { |
Rob Landley | c983274 | 2006-06-24 21:27:36 +0000 | [diff] [blame] | 157 | if (link(link_name, dest) < 0) { |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 158 | ovr = retry_overwrite(dest, flags); |
| 159 | if (ovr <= 0) |
| 160 | return ovr; |
| 161 | if (link(link_name, dest) < 0) { |
| 162 | bb_perror_msg("cannot create link '%s'", dest); |
| 163 | return -1; |
| 164 | } |
Rob Landley | c983274 | 2006-06-24 21:27:36 +0000 | [diff] [blame] | 165 | } |
Rob Landley | c983274 | 2006-06-24 21:27:36 +0000 | [diff] [blame] | 166 | return 0; |
Matt Kraai | ace02dc | 2001-12-17 15:26:36 +0000 | [diff] [blame] | 167 | } |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 168 | // TODO: probably is_in_.. and add_to_... |
| 169 | // can be combined: find_or_add_... |
Rob Landley | c983274 | 2006-06-24 21:27:36 +0000 | [diff] [blame] | 170 | add_to_ino_dev_hashtable(&source_stat, dest); |
Matt Kraai | ace02dc | 2001-12-17 15:26:36 +0000 | [diff] [blame] | 171 | } |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 172 | |
Glenn L McGrath | f62ea20 | 2003-12-20 04:38:01 +0000 | [diff] [blame] | 173 | src_fd = open(source, O_RDONLY); |
| 174 | if (src_fd == -1) { |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 175 | bb_perror_msg("cannot open '%s'", source); |
| 176 | return -1; |
Matt Kraai | 14b7c5d | 2001-12-11 16:43:48 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 179 | // POSIX: if exists and -i, ask (w/o -i assume yes). |
| 180 | // Then open w/o EXCL. |
| 181 | // If open still fails and -f, try unlink, then try open again. |
| 182 | // Result: a mess: |
| 183 | // If dest is a softlink, we overwrite softlink's destination! |
| 184 | // (or fail, if it points to dir/nonexistent location/etc). |
| 185 | // This is strange, but POSIX-correct. |
| 186 | // coreutils cp has --remove-destination to override this... |
| 187 | dst_fd = open(dest, (flags & FILEUTILS_INTERACTIVE) |
| 188 | ? O_WRONLY|O_CREAT|O_TRUNC|O_EXCL |
| 189 | : O_WRONLY|O_CREAT|O_TRUNC, source_stat.st_mode); |
| 190 | if (dst_fd == -1) { |
| 191 | // We would not do POSIX insanity. -i asks, |
| 192 | // then _unlinks_ the offender. Presto. |
| 193 | // Or else we will end up having 3 open()s! |
| 194 | ovr = retry_overwrite(dest, flags); |
| 195 | if (ovr <= 0) { |
Glenn L McGrath | f62ea20 | 2003-12-20 04:38:01 +0000 | [diff] [blame] | 196 | close(src_fd); |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 197 | return ovr; |
| 198 | } |
| 199 | dst_fd = open(dest, O_WRONLY|O_CREAT|O_TRUNC, source_stat.st_mode); |
| 200 | if (dst_fd == -1) { |
| 201 | bb_perror_msg("cannot open '%s'", dest); |
| 202 | close(src_fd); |
| 203 | return -1; |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | |
Glenn L McGrath | f62ea20 | 2003-12-20 04:38:01 +0000 | [diff] [blame] | 207 | if (bb_copyfd_eof(src_fd, dst_fd) == -1) |
Matt Kraai | bf0a010 | 2001-06-11 13:58:02 +0000 | [diff] [blame] | 208 | status = -1; |
Glenn L McGrath | f62ea20 | 2003-12-20 04:38:01 +0000 | [diff] [blame] | 209 | if (close(dst_fd) < 0) { |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 210 | bb_perror_msg("cannot close '%s'", dest); |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 211 | status = -1; |
| 212 | } |
Glenn L McGrath | f62ea20 | 2003-12-20 04:38:01 +0000 | [diff] [blame] | 213 | if (close(src_fd) < 0) { |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 214 | bb_perror_msg("cannot close '%s'", source); |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 215 | status = -1; |
| 216 | } |
Eric Andersen | 403a73a | 2002-09-16 09:23:22 +0000 | [diff] [blame] | 217 | |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 218 | } else if (S_ISBLK(source_stat.st_mode) || S_ISCHR(source_stat.st_mode) |
| 219 | || S_ISSOCK(source_stat.st_mode) || S_ISFIFO(source_stat.st_mode) |
| 220 | || S_ISLNK(source_stat.st_mode) |
| 221 | ) { |
| 222 | // We are lazy here, a bit lax with races... |
Paul Fox | 0a92bbf | 2005-07-19 20:47:33 +0000 | [diff] [blame] | 223 | if (dest_exists) { |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 224 | ovr = retry_overwrite(dest, flags); |
| 225 | if (ovr <= 0) |
| 226 | return ovr; |
Paul Fox | 0a92bbf | 2005-07-19 20:47:33 +0000 | [diff] [blame] | 227 | } |
Rob Landley | 2f30932 | 2005-11-01 21:55:14 +0000 | [diff] [blame] | 228 | if (S_ISFIFO(source_stat.st_mode)) { |
| 229 | if (mkfifo(dest, source_stat.st_mode) < 0) { |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 230 | bb_perror_msg("cannot create fifo '%s'", dest); |
Rob Landley | 2f30932 | 2005-11-01 21:55:14 +0000 | [diff] [blame] | 231 | return -1; |
| 232 | } |
| 233 | } else if (S_ISLNK(source_stat.st_mode)) { |
| 234 | char *lpath; |
| 235 | |
| 236 | lpath = xreadlink(source); |
| 237 | if (symlink(lpath, dest) < 0) { |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 238 | bb_perror_msg("cannot create symlink '%s'", dest); |
| 239 | free(lpath); |
Rob Landley | 2f30932 | 2005-11-01 21:55:14 +0000 | [diff] [blame] | 240 | return -1; |
| 241 | } |
| 242 | free(lpath); |
| 243 | |
| 244 | if (flags & FILEUTILS_PRESERVE_STATUS) |
| 245 | if (lchown(dest, source_stat.st_uid, source_stat.st_gid) < 0) |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 246 | bb_perror_msg("cannot preserve %s of '%s'", "ownership", dest); |
Rob Landley | 2f30932 | 2005-11-01 21:55:14 +0000 | [diff] [blame] | 247 | |
| 248 | return 0; |
| 249 | |
| 250 | } else { |
| 251 | if (mknod(dest, source_stat.st_mode, source_stat.st_rdev) < 0) { |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 252 | bb_perror_msg("cannot create '%s'", dest); |
Rob Landley | 2f30932 | 2005-11-01 21:55:14 +0000 | [diff] [blame] | 253 | return -1; |
| 254 | } |
| 255 | } |
Eric Andersen | a9a220b | 2002-09-17 08:42:21 +0000 | [diff] [blame] | 256 | } else { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 257 | bb_error_msg("internal error: unrecognized file type"); |
Eric Andersen | a9a220b | 2002-09-17 08:42:21 +0000 | [diff] [blame] | 258 | return -1; |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 259 | } |
| 260 | |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 261 | preserve_status: |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 262 | |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 263 | if (flags & FILEUTILS_PRESERVE_STATUS |
| 264 | /* Cannot happen: */ |
| 265 | /* && !(flags & (FILEUTILS_MAKE_SOFTLINK|FILEUTILS_MAKE_HARDLINK)) */ |
| 266 | ) { |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 267 | struct utimbuf times; |
| 268 | |
| 269 | times.actime = source_stat.st_atime; |
| 270 | times.modtime = source_stat.st_mtime; |
| 271 | if (utime(dest, ×) < 0) |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 272 | bb_perror_msg("cannot preserve %s of '%s'", "times", dest); |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 273 | if (chown(dest, source_stat.st_uid, source_stat.st_gid) < 0) { |
| 274 | source_stat.st_mode &= ~(S_ISUID | S_ISGID); |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 275 | bb_perror_msg("cannot preserve %s of '%s'", "ownership", dest); |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 276 | } |
| 277 | if (chmod(dest, source_stat.st_mode) < 0) |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 278 | bb_perror_msg("cannot preserve %s of '%s'", "permissions", dest); |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 279 | } |
| 280 | |
Matt Kraai | 24abecc | 2001-04-30 16:37:04 +0000 | [diff] [blame] | 281 | return status; |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 282 | } |