mirror of
https://github.com/sheumann/hush.git
synced 2025-01-12 14:30:54 +00:00
fake out support for POSIX -H and -L options since busybox cp dereferences everything by default
This commit is contained in:
parent
75ac42b1ae
commit
2ed05ab146
@ -42,7 +42,7 @@
|
|||||||
#include "libcoreutils/coreutils.h"
|
#include "libcoreutils/coreutils.h"
|
||||||
|
|
||||||
/* WARNING!! ORDER IS IMPORTANT!! */
|
/* WARNING!! ORDER IS IMPORTANT!! */
|
||||||
static const char cp_opts[] = "pdRfiarP";
|
static const char cp_opts[] = "pdRfiarPHL";
|
||||||
|
|
||||||
extern int cp_main(int argc, char **argv)
|
extern int cp_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
@ -70,7 +70,7 @@ extern int cp_main(int argc, char **argv)
|
|||||||
if (flags & 64) {
|
if (flags & 64) {
|
||||||
/* Make -r a synonym for -R,
|
/* Make -r a synonym for -R,
|
||||||
* -r was marked as obsolete in SUSv3, but is included for compatability
|
* -r was marked as obsolete in SUSv3, but is included for compatability
|
||||||
*/
|
*/
|
||||||
flags |= FILEUTILS_RECUR;
|
flags |= FILEUTILS_RECUR;
|
||||||
}
|
}
|
||||||
if (flags & 128) {
|
if (flags & 128) {
|
||||||
@ -79,6 +79,14 @@ extern int cp_main(int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
flags |= FILEUTILS_DEREFERENCE;
|
flags |= FILEUTILS_DEREFERENCE;
|
||||||
}
|
}
|
||||||
|
/* Default behavior of cp is to dereference, so we don't have to do
|
||||||
|
* anything special when we are given -L.
|
||||||
|
* The behavior of -H is *almost* like -L, but not quite, so let's
|
||||||
|
* just ignore it too for fun.
|
||||||
|
if (flags & 256 || flags & 512) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
flags ^= FILEUTILS_DEREFERENCE; /* The sense of this flag was reversed. */
|
flags ^= FILEUTILS_DEREFERENCE; /* The sense of this flag was reversed. */
|
||||||
|
|
||||||
@ -92,7 +100,7 @@ extern int cp_main(int argc, char **argv)
|
|||||||
/* If there are only two arguments and... */
|
/* If there are only two arguments and... */
|
||||||
if (optind + 2 == argc) {
|
if (optind + 2 == argc) {
|
||||||
s_flags = cp_mv_stat2(*argv, &source_stat,
|
s_flags = cp_mv_stat2(*argv, &source_stat,
|
||||||
(flags & FILEUTILS_DEREFERENCE) ? stat : lstat);
|
(flags & FILEUTILS_DEREFERENCE) ? stat : lstat);
|
||||||
if ((s_flags < 0) || ((d_flags = cp_mv_stat(last, &dest_stat)) < 0)) {
|
if ((s_flags < 0) || ((d_flags = cp_mv_stat(last, &dest_stat)) < 0)) {
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@ -104,8 +112,8 @@ extern int cp_main(int argc, char **argv)
|
|||||||
((((flags & FILEUTILS_RECUR) >> 1) & s_flags) && !d_flags)
|
((((flags & FILEUTILS_RECUR) >> 1) & s_flags) && !d_flags)
|
||||||
) {
|
) {
|
||||||
/* ...do a simple copy. */
|
/* ...do a simple copy. */
|
||||||
dest = last;
|
dest = last;
|
||||||
goto DO_COPY; /* Note: optind+2==argc implies argv[1]==last below. */
|
goto DO_COPY; /* Note: optind+2==argc implies argv[1]==last below. */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,6 +205,7 @@
|
|||||||
"\n" \
|
"\n" \
|
||||||
"\t-a\tSame as -dpR\n" \
|
"\t-a\tSame as -dpR\n" \
|
||||||
"\t-d,-P\tPreserves links\n" \
|
"\t-d,-P\tPreserves links\n" \
|
||||||
|
"\t-H,-L\tDereference all symlinks (implied by default)\n" \
|
||||||
"\t-p\tPreserves file attributes if possible\n" \
|
"\t-p\tPreserves file attributes if possible\n" \
|
||||||
"\t-f\tforce (implied; ignored) - always set\n" \
|
"\t-f\tforce (implied; ignored) - always set\n" \
|
||||||
"\t-i\tinteractive, prompt before overwrite\n" \
|
"\t-i\tinteractive, prompt before overwrite\n" \
|
||||||
|
@ -54,10 +54,11 @@ int copy_file(const char *source, const char *dest, int flags)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (source_stat.st_dev == dest_stat.st_dev &&
|
if (source_stat.st_dev == dest_stat.st_dev &&
|
||||||
source_stat.st_ino == dest_stat.st_ino) {
|
source_stat.st_ino == dest_stat.st_ino)
|
||||||
bb_error_msg("`%s' and `%s' are the same file", source, dest);
|
{
|
||||||
return -1;
|
bb_error_msg("`%s' and `%s' are the same file", source, dest);
|
||||||
}
|
return -1;
|
||||||
|
}
|
||||||
dest_exists = 1;
|
dest_exists = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user