1303 files changed, 32187 insertions, 57138 deletions
diff --git a/coreutils/cp.c b/coreutils/cp.c index de2e512..4ecdaaf 100644 --- a/coreutils/cp.c +++ b/coreutils/cp.c @@ -7,13 +7,29 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - -/* http://www.opengroup.org/onlinepubs/007904975/utilities/cp.html */ - /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org) * * Size reduction. */ +//config:config CP +//config: bool "cp" +//config: default y +//config: help +//config: cp is used to copy files and directories. +//config: +//config:config FEATURE_CP_LONG_OPTIONS +//config: bool "Enable long options for cp" +//config: default y +//config: depends on CP && LONG_OPTS +//config: help +//config: Enable long options for cp. +//config: Also add support for --parents option. + +//applet:IF_CP(APPLET_NOEXEC(cp, cp, BB_DIR_BIN, BB_SUID_DROP, cp)) + +//kbuild:lib-$(CONFIG_CP) += cp.o + +/* http://www.opengroup.org/onlinepubs/007904975/utilities/cp.html */ //usage:#define cp_trivial_usage //usage: "[OPTIONS] SOURCE... DEST" @@ -31,6 +47,7 @@ //usage: "\n -f Overwrite" //usage: "\n -i Prompt before overwrite" //usage: "\n -l,-s Create (sym)links" +//usage: "\n -u Copy only newer files" #include "libbb.h" #include "libcoreutils/coreutils.h" @@ -49,12 +66,10 @@ int cp_main(int argc, char **argv) int flags; int status; enum { - OPT_a = 1 << (sizeof(FILEUTILS_CP_OPTSTR)-1), - OPT_r = 1 << (sizeof(FILEUTILS_CP_OPTSTR)), - OPT_P = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+1), - OPT_v = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+2), + FILEUTILS_CP_OPTNUM = sizeof(FILEUTILS_CP_OPTSTR)-1, #if ENABLE_FEATURE_CP_LONG_OPTIONS - OPT_parents = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+3), + /*OPT_rmdest = FILEUTILS_RMDEST = 1 << FILEUTILS_CP_OPTNUM */ + OPT_parents = 1 << (FILEUTILS_CP_OPTNUM+1), #endif }; @@ -76,11 +91,12 @@ int cp_main(int argc, char **argv) "recursive\0" No_argument "R" "symbolic-link\0" No_argument "s" "verbose\0" No_argument "v" - "parents\0" No_argument "\xff" + "update\0" No_argument "u" + "remove-destination\0" No_argument "\xff" + "parents\0" No_argument "\xfe" ; #endif - // -v (--verbose) is ignored - flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPv"); + flags = getopt32(argv, FILEUTILS_CP_OPTSTR); /* Options of cp from GNU coreutils 6.10: * -a, --archive * -f, --force @@ -95,6 +111,11 @@ int cp_main(int argc, char **argv) * -d same as --no-dereference --preserve=links * -p same as --preserve=mode,ownership,timestamps * -c same as --preserve=context + * -u, --update + * copy only when the SOURCE file is newer than the destination + * file or when the destination file is missing + * --remove-destination + * remove each existing destination file before attempting to open * --parents * use full source file name under DIRECTORY * NOT SUPPORTED IN BBOX: @@ -107,8 +128,6 @@ int cp_main(int argc, char **argv) * preserve attributes (default: mode,ownership,timestamps), * if possible additional attributes: security context,links,all * --no-preserve=ATTR_LIST - * --remove-destination - * remove each existing destination file before attempting to open * --sparse=WHEN * control creation of sparse files * --strip-trailing-slashes @@ -119,9 +138,6 @@ int cp_main(int argc, char **argv) * copy all SOURCE arguments into DIRECTORY * -T, --no-target-directory * treat DEST as a normal file - * -u, --update - * copy only when the SOURCE file is newer than the destination - * file or when the destination file is missing * -x, --one-file-system * stay on this file system * -Z, --context=CONTEXT @@ -157,11 +173,16 @@ int cp_main(int argc, char **argv) return EXIT_FAILURE; #if ENABLE_FEATURE_CP_LONG_OPTIONS + //bb_error_msg("flags:%x FILEUTILS_RMDEST:%x OPT_parents:%x", + // flags, FILEUTILS_RMDEST, OPT_parents); if (flags & OPT_parents) { if (!(d_flags & 2)) { bb_error_msg_and_die("with --parents, the destination must be a directory"); } } + if (flags & FILEUTILS_RMDEST) { + flags |= FILEUTILS_FORCE; + } #endif /* ...if neither is a directory... */ |