aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2006-06-24 21:27:36 +0000
committerRob Landley <rob@landley.net>2006-06-24 21:27:36 +0000
commitc983274565a3443177ba1a68aab23a61ae70d5ea (patch)
tree2b8f914ab92544031b385a2ced99df20577263b7
parent5d9c42aadc7a526faa58bc94b9bdb650595f9d24 (diff)
downloadbusybox-w32-c983274565a3443177ba1a68aab23a61ae70d5ea.tar.gz
busybox-w32-c983274565a3443177ba1a68aab23a61ae70d5ea.tar.bz2
busybox-w32-c983274565a3443177ba1a68aab23a61ae70d5ea.zip
The logic to make cp -d or -P treat things like regular files should only
trigger for symlinks, not for device nodes. This should fix "cp -a /dev ." to work as expected (when run by root, anyway). While I was there, cleanup headers and make an #ifdef go away...
-rw-r--r--libbb/copy_file.c35
1 files changed, 14 insertions, 21 deletions
diff --git a/libbb/copy_file.c b/libbb/copy_file.c
index a4da92218..38a2cb9c3 100644
--- a/libbb/copy_file.c
+++ b/libbb/copy_file.c
@@ -8,17 +8,9 @@
8 * 8 *
9 */ 9 */
10 10
11#include <sys/types.h> 11#include "libbb.h"
12#include <sys/stat.h>
13#include <unistd.h>
14#include <fcntl.h>
15#include <utime.h> 12#include <utime.h>
16#include <errno.h> 13#include <errno.h>
17#include <dirent.h>
18#include <stdlib.h>
19#include <string.h>
20
21#include "libbb.h"
22 14
23int copy_file(const char *source, const char *dest, int flags) 15int copy_file(const char *source, const char *dest, int flags)
24{ 16{
@@ -110,24 +102,25 @@ int copy_file(const char *source, const char *dest, int flags)
110 bb_perror_msg("unable to change permissions of `%s'", dest); 102 bb_perror_msg("unable to change permissions of `%s'", dest);
111 status = -1; 103 status = -1;
112 } 104 }
113 } else if (S_ISREG(source_stat.st_mode) || (flags & FILEUTILS_DEREFERENCE)) 105 } else if (S_ISREG(source_stat.st_mode) ||
106 (S_ISLNK(source_stat.st_mode) && (flags & FILEUTILS_DEREFERENCE)))
114 { 107 {
115 int src_fd; 108 int src_fd;
116 int dst_fd; 109 int dst_fd;
117#ifdef CONFIG_FEATURE_PRESERVE_HARDLINKS 110 if (ENABLE_FEATURE_PRESERVE_HARDLINKS) {
118 char *link_name; 111 char *link_name;
119 112
120 if (!(flags & FILEUTILS_DEREFERENCE) && 113 if (!(flags & FILEUTILS_DEREFERENCE) &&
121 is_in_ino_dev_hashtable(&source_stat, &link_name)) { 114 is_in_ino_dev_hashtable(&source_stat, &link_name)) {
122 if (link(link_name, dest) < 0) { 115 if (link(link_name, dest) < 0) {
123 bb_perror_msg("unable to link `%s'", dest); 116 bb_perror_msg("unable to link `%s'", dest);
124 return -1; 117 return -1;
125 } 118 }
126 119
127 return 0; 120 return 0;
121 }
122 add_to_ino_dev_hashtable(&source_stat, dest);
128 } 123 }
129 add_to_ino_dev_hashtable(&source_stat, dest);
130#endif
131 src_fd = open(source, O_RDONLY); 124 src_fd = open(source, O_RDONLY);
132 if (src_fd == -1) { 125 if (src_fd == -1) {
133 bb_perror_msg("unable to open `%s'", source); 126 bb_perror_msg("unable to open `%s'", source);