From: Jim Meyering Date: Wed, 30 Jun 2004 18:38:24 +0000 (+0000) Subject: Add support for --no-target-directory option. X-Git-Tag: COREUTILS-5_3_0~1225 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7ed69a972c256dfa7dc606250777bf0c613d57c8;p=platform%2Fupstream%2Fcoreutils.git Add support for --no-target-directory option. (NO_TARGET_DIRECTORY_OPTION): New constant. (long_opts, usage, do_copy, main): Add support for --- diff --git a/src/cp.c b/src/cp.c index 56c4a5a..0a9f65a 100644 --- a/src/cp.c +++ b/src/cp.c @@ -70,6 +70,7 @@ enum { COPY_CONTENTS_OPTION = CHAR_MAX + 1, NO_PRESERVE_ATTRIBUTES_OPTION, + NO_TARGET_DIRECTORY_OPTION, PARENTS_OPTION, PRESERVE_ATTRIBUTES_OPTION, REPLY_OPTION, @@ -128,6 +129,7 @@ static struct option const long_opts[] = {"link", no_argument, NULL, 'l'}, {"no-dereference", no_argument, NULL, 'P'}, {"no-preserve", required_argument, NULL, NO_PRESERVE_ATTRIBUTES_OPTION}, + {"no-target-directory", no_argument, NULL, NO_TARGET_DIRECTORY_OPTION}, {"one-file-system", no_argument, NULL, 'x'}, {"parents", no_argument, NULL, PARENTS_OPTION}, {"path", no_argument, NULL, PARENTS_OPTION}, /* Deprecated. */ @@ -212,6 +214,7 @@ Mandatory arguments to long options are mandatory for short options too.\n\ -s, --symbolic-link make symbolic links instead of copying\n\ -S, --suffix=SUFFIX override the usual backup suffix\n\ --target-directory=DIRECTORY copy all SOURCE arguments into DIRECTORY\n\ + --no-target-directory treat DEST as a normal file\n\ "), stdout); fputs (_("\ -u, --update copy only when the SOURCE file is newer\n\ @@ -495,7 +498,7 @@ target_directory_operand (char const *file, struct stat *st, int *errp) static int do_copy (int n_files, char **file, const char *target_directory, - struct cp_options *x) + bool no_target_directory, struct cp_options *x) { struct stat sb; int new_dst = 0; @@ -511,7 +514,19 @@ do_copy (int n_files, char **file, const char *target_directory, usage (EXIT_FAILURE); } - if (!target_directory) + if (no_target_directory) + { + if (target_directory) + error (EXIT_FAILURE, 0, + _("Cannot combine --target-directory " + "and --no-target-directory")); + if (2 < n_files) + { + error (0, 0, _("extra operand %s"), quote (file[2])); + usage (EXIT_FAILURE); + } + } + else if (!target_directory) { if (2 <= n_files && target_directory_operand (file[n_files - 1], &sb, &new_dst)) @@ -793,6 +808,7 @@ main (int argc, char **argv) struct cp_options x; int copy_contents = 0; char *target_directory = NULL; + bool no_target_directory = false; initialize_main (&argc, &argv); program_name = argv[0]; @@ -881,6 +897,10 @@ main (int argc, char **argv) decode_preserve_arg (optarg, &x, 0); break; + case NO_TARGET_DIRECTORY_OPTION: + no_target_directory = true; + break; + case PRESERVE_ATTRIBUTES_OPTION: if (optarg == NULL) { @@ -1014,7 +1034,8 @@ main (int argc, char **argv) hash_init (); - exit_status = do_copy (argc - optind, argv + optind, target_directory, &x); + exit_status = do_copy (argc - optind, argv + optind, + target_directory, no_target_directory, &x); forget_all ();