cp: fix -H handling

function                                             old     new   delta
copy_file                                           1495    1518     +23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko
2010-01-15 22:05:07 +01:00
parent 662078f9fd
commit a40f0624db
5 changed files with 227 additions and 24 deletions

View File

@ -35,10 +35,9 @@ int cp_main(int argc, char **argv)
OPT_a = 1 << (sizeof(FILEUTILS_CP_OPTSTR)-1),
OPT_r = 1 << (sizeof(FILEUTILS_CP_OPTSTR)),
OPT_P = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+1),
OPT_H = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+2),
OPT_v = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+3),
OPT_v = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+2),
#if ENABLE_FEATURE_CP_LONG_OPTIONS
OPT_parents = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+4),
OPT_parents = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+3),
#endif
};
@ -48,7 +47,7 @@ int cp_main(int argc, char **argv)
// -r and -R are the same
// -R (and therefore -r) turns on -d (coreutils does this)
// -a = -pdR
opt_complementary = "-2:l--s:s--l:Pd:rRd:Rd:apdR:HL";
opt_complementary = "-2:l--s:s--l:Pd:rRd:Rd:apdR";
#if ENABLE_FEATURE_CP_LONG_OPTIONS
applet_long_options =
"archive\0" No_argument "a"
@ -64,7 +63,7 @@ int cp_main(int argc, char **argv)
;
#endif
// -v (--verbose) is ignored
flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPHv");
flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPv");
/* Options of cp from GNU coreutils 6.10:
* -a, --archive
* -f, --force
@ -113,17 +112,14 @@ int cp_main(int argc, char **argv)
*/
argc -= optind;
argv += optind;
flags ^= FILEUTILS_DEREFERENCE; /* the sense of this flag was reversed */
/* Reverse this bit. If there is -d, bit is not set: */
flags ^= FILEUTILS_DEREFERENCE;
/* coreutils 6.9 compat:
* by default, "cp" derefs symlinks (creates regular dest files),
* but "cp -R" does not. We switch off deref if -r or -R (see above).
* However, "cp -RL" must still deref symlinks: */
if (flags & FILEUTILS_DEREF_SOFTLINK) /* -L */
flags |= FILEUTILS_DEREFERENCE;
/* The behavior of -H is *almost* like -L, but not quite, so let's
* just ignore it too for fun. TODO.
if (flags & OPT_H) ... // deref command-line params only
*/
#if ENABLE_SELINUX
if (flags & FILEUTILS_PRESERVE_SECURITY_CONTEXT) {