diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-04-27 22:06:24 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-04-27 22:06:24 +0000 |
commit | c0431ed455a601ddbfcd9f30d6397d4e9145cf54 (patch) | |
tree | 7eade59699338d065827751d37e72e45d2b4440b | |
parent | 4809a9f78eecc7346e5d73b7f60ae6c51e057632 (diff) | |
download | busybox-w32-c0431ed455a601ddbfcd9f30d6397d4e9145cf54.tar.gz busybox-w32-c0431ed455a601ddbfcd9f30d6397d4e9145cf54.tar.bz2 busybox-w32-c0431ed455a601ddbfcd9f30d6397d4e9145cf54.zip |
cp: fix "cp -RL" to create regular files even if src is a symlink
-rwxr-xr-x | applets/install.sh | 2 | ||||
-rw-r--r-- | coreutils/cp.c | 22 | ||||
-rw-r--r-- | include/libbb.h | 7 | ||||
-rw-r--r-- | testsuite/cp/cp-RHL-does_not_preserve-links | 6 |
4 files changed, 23 insertions, 14 deletions
diff --git a/applets/install.sh b/applets/install.sh index e94b2b98e..32049b157 100755 --- a/applets/install.sh +++ b/applets/install.sh | |||
@@ -37,7 +37,7 @@ if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then | |||
37 | for i in $DO_INSTALL_LIBS; do | 37 | for i in $DO_INSTALL_LIBS; do |
38 | rm -f $prefix/$libdir/$i || exit 1 | 38 | rm -f $prefix/$libdir/$i || exit 1 |
39 | if [ -f $i ]; then | 39 | if [ -f $i ]; then |
40 | cp -a $i $prefix/$libdir/ || exit 1 | 40 | cp -pPR $i $prefix/$libdir/ || exit 1 |
41 | chmod 0644 $prefix/$libdir/$i || exit 1 | 41 | chmod 0644 $prefix/$libdir/$i || exit 1 |
42 | fi | 42 | fi |
43 | done | 43 | done |
diff --git a/coreutils/cp.c b/coreutils/cp.c index a4eea9498..40d3625b3 100644 --- a/coreutils/cp.c +++ b/coreutils/cp.c | |||
@@ -37,25 +37,27 @@ int cp_main(int argc, char **argv) | |||
37 | OPT_r = 1 << (sizeof(FILEUTILS_CP_OPTSTR)), | 37 | OPT_r = 1 << (sizeof(FILEUTILS_CP_OPTSTR)), |
38 | OPT_P = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+1), | 38 | OPT_P = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+1), |
39 | OPT_H = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+2), | 39 | OPT_H = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+2), |
40 | OPT_L = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+3), | ||
41 | }; | 40 | }; |
42 | 41 | ||
43 | // Need at least two arguments | 42 | // Need at least two arguments |
44 | // Soft- and hardlinking don't mix | 43 | // Soft- and hardlinking doesn't mix |
45 | // -P and -d are the same (-P is POSIX, -d is GNU) | 44 | // -P and -d are the same (-P is POSIX, -d is GNU) |
46 | // -r and -R are the same | 45 | // -r and -R are the same |
47 | // -R (and therefore -r) turns on -d (coreutils does this) | 46 | // -R (and therefore -r) turns on -d (coreutils does this) |
48 | // -a = -pdR | 47 | // -a = -pdR |
49 | opt_complementary = "-2:l--s:s--l:Pd:rRd:Rd:apdR"; | 48 | opt_complementary = "-2:l--s:s--l:Pd:rRd:Rd:apdR:HL"; |
50 | flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPHL"); | 49 | flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPH"); |
51 | argc -= optind; | 50 | argc -= optind; |
52 | argv += optind; | 51 | argv += optind; |
53 | flags ^= FILEUTILS_DEREFERENCE; /* The sense of this flag was reversed. */ | 52 | flags ^= FILEUTILS_DEREFERENCE; /* the sense of this flag was reversed */ |
54 | /* Default behavior of cp is to dereference, so we don't have to do | 53 | /* coreutils 6.9 compat: |
55 | * anything special when we are given -L. | 54 | * by default, "cp" derefs symlinks (creates regular dest files), |
56 | * The behavior of -H is *almost* like -L, but not quite, so let's | 55 | * but "cp -R" does not. We switch off deref if -r or -R (see above). |
57 | * just ignore it too for fun. | 56 | * However, "cp -RL" must still deref symlinks: */ |
58 | if (flags & OPT_L) ... | 57 | if (flags & FILEUTILS_DEREF_SOFTLINK) /* -L */ |
58 | flags |= FILEUTILS_DEREFERENCE; | ||
59 | /* The behavior of -H is *almost* like -L, but not quite, so let's | ||
60 | * just ignore it too for fun. TODO. | ||
59 | if (flags & OPT_H) ... // deref command-line params only | 61 | if (flags & OPT_H) ... // deref command-line params only |
60 | */ | 62 | */ |
61 | 63 | ||
diff --git a/include/libbb.h b/include/libbb.h index 7a8bfdffb..dfcc96d5b 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -231,12 +231,13 @@ enum { /* DO NOT CHANGE THESE VALUES! cp.c, mv.c, install.c depend on them. */ | |||
231 | FILEUTILS_INTERACTIVE = 0x10, | 231 | FILEUTILS_INTERACTIVE = 0x10, |
232 | FILEUTILS_MAKE_HARDLINK = 0x20, | 232 | FILEUTILS_MAKE_HARDLINK = 0x20, |
233 | FILEUTILS_MAKE_SOFTLINK = 0x40, | 233 | FILEUTILS_MAKE_SOFTLINK = 0x40, |
234 | FILEUTILS_DEREF_SOFTLINK = 0x80, | ||
234 | #if ENABLE_SELINUX | 235 | #if ENABLE_SELINUX |
235 | FILEUTILS_PRESERVE_SECURITY_CONTEXT = 0x80, | 236 | FILEUTILS_PRESERVE_SECURITY_CONTEXT = 0x100, |
236 | FILEUTILS_SET_SECURITY_CONTEXT = 0x100 | 237 | FILEUTILS_SET_SECURITY_CONTEXT = 0x200 |
237 | #endif | 238 | #endif |
238 | }; | 239 | }; |
239 | #define FILEUTILS_CP_OPTSTR "pdRfils" USE_SELINUX("c") | 240 | #define FILEUTILS_CP_OPTSTR "pdRfilsL" USE_SELINUX("c") |
240 | extern int remove_file(const char *path, int flags); | 241 | extern int remove_file(const char *path, int flags); |
241 | /* NB: without FILEUTILS_RECUR in flags, it will basically "cat" | 242 | /* NB: without FILEUTILS_RECUR in flags, it will basically "cat" |
242 | * the source, not copy (unless "source" is a directory). | 243 | * the source, not copy (unless "source" is a directory). |
diff --git a/testsuite/cp/cp-RHL-does_not_preserve-links b/testsuite/cp/cp-RHL-does_not_preserve-links new file mode 100644 index 000000000..eed6c3ec5 --- /dev/null +++ b/testsuite/cp/cp-RHL-does_not_preserve-links | |||
@@ -0,0 +1,6 @@ | |||
1 | mkdir a | ||
2 | >a/file | ||
3 | ln -s file a/link | ||
4 | busybox cp -RHL a b | ||
5 | test ! -L b/link | ||
6 | #sh </dev/tty >/dev/tty 2>&1 | ||