summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2000-04-16 13:51:22 +0000
committerJim Meyering <jim@meyering.net>2000-04-16 13:51:22 +0000
commitc559eefb84a385bec79c96ba13647f346acf2c03 (patch)
tree1d13f79350b414723d281d25f80334bf61e00bb4 /src
parent517e8a6bc2220d0df3889daad90c19729398009b (diff)
downloadcoreutils-c559eefb84a385bec79c96ba13647f346acf2c03.tar.xz
New option: --strip-trailing-slashes.
(enum) [STRIP_TRAILING_SLASHES_OPTION]: New member. (remove_trailing_slashes): New global. (long_opts): New getopt spec. (usage): Describe. (do_copy): Strip trailing slashes on SOURCE names only if the new option has been specified. (main): New case.
Diffstat (limited to 'src')
-rw-r--r--src/cp.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/cp.c b/src/cp.c
index 4c214b5c0..460028940 100644
--- a/src/cp.c
+++ b/src/cp.c
@@ -60,7 +60,8 @@ struct dir_attr
enum
{
TARGET_DIRECTORY_OPTION = CHAR_MAX + 1,
- SPARSE_OPTION
+ SPARSE_OPTION,
+ STRIP_TRAILING_SLASHES_OPTION
};
int stat ();
@@ -81,6 +82,9 @@ char *program_name;
as its destination instead of the usual "e_dir/e_file." */
static int flag_path = 0;
+/* Remove any trailing slashes from each SOURCE argument. */
+static int remove_trailing_slashes;
+
static char const *const sparse_type_string[] =
{
"never", "auto", "always", 0
@@ -108,6 +112,7 @@ static struct option const long_opts[] =
{"path", no_argument, NULL, 'P'},
{"preserve", no_argument, NULL, 'p'},
{"recursive", no_argument, NULL, 'R'},
+ {"strip-trailing-slash", no_argument, NULL, STRIP_TRAILING_SLASHES_OPTION},
{"suffix", required_argument, NULL, 'S'},
{"symbolic-link", no_argument, NULL, 's'},
{"target-directory", required_argument, NULL, TARGET_DIRECTORY_OPTION},
@@ -150,6 +155,8 @@ Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.\n\
special files like FIFOs or /dev/zero\n\
--sparse=WHEN control creation of sparse files\n\
-R, --recursive copy directories recursively\n\
+ --strip-trailing-slashes remove any trailing slashes from each SOURCE\n\
+ argument\n\
-s, --symbolic-link make symbolic links instead of copying\n\
-S, --suffix=SUFFIX override the usual backup suffix\n\
--target-directory=DIRECTORY move all SOURCE arguments into DIRECTORY\n\
@@ -486,7 +493,8 @@ do_copy (int n_files, char **file, const char *target_directory,
char *arg_in_concat = NULL;
char *arg = file[i];
- strip_trailing_slashes (arg);
+ if (remove_trailing_slashes)
+ strip_trailing_slashes (arg);
if (flag_path)
{
@@ -598,7 +606,8 @@ do_copy (int n_files, char **file, const char *target_directory,
tmp_source = (char *) alloca (strlen (source) + 1);
strcpy (tmp_source, source);
- strip_trailing_slashes (tmp_source);
+ if (remove_trailing_slashes)
+ strip_trailing_slashes (tmp_source);
source_base = base_name (tmp_source);
new_dest = (char *) alloca (strlen (dest)
@@ -746,6 +755,10 @@ main (int argc, char **argv)
x.copy_as_regular = 0;
break;
+ case STRIP_TRAILING_SLASHES_OPTION:
+ remove_trailing_slashes = 1;
+ break;
+
case 's':
#ifdef S_ISLNK
x.symbolic_link = 1;