(do_copy): When constructing dst_path for use with the
authorJim Meyering <jim@meyering.net>
Sun, 29 Oct 2000 12:25:03 +0000 (12:25 +0000)
committerJim Meyering <jim@meyering.net>
Sun, 29 Oct 2000 12:25:03 +0000 (12:25 +0000)
--parents option, first remove any trailing slashes from the command
line argument.  Otherwise, tests/cp/cp-parent would fail on NetBSD.

src/cp.c

index 70cd36c..9db7c5f 100644 (file)
--- a/src/cp.c
+++ b/src/cp.c
@@ -518,13 +518,26 @@ do_copy (int n_files, char **file, const char *target_directory,
          char *arg_in_concat = NULL;
          char *arg = file[i];
 
+         /* Trailing slashes are meaningful (i.e., maybe worth preserving)
+            only in the source file names.  */
          if (remove_trailing_slashes)
            strip_trailing_slashes (arg);
 
          if (flag_path)
            {
-             /* Append all of `arg' to `dest'.  */
-             dst_path = path_concat (dest, arg, &arg_in_concat);
+             char *arg_no_trailing_slash;
+
+             /* Use `arg' without trailing slashes in constructing destination
+                file names.  Otherwise, we can end up trying to create a
+                directory via `mkdir ("dst/foo/"...', which is not portable.
+                It fails, due to the trailing slash, on at least
+                NetBSD 1.[34] systems.  */
+             ASSIGN_STRDUPA (arg_no_trailing_slash, arg);
+             strip_trailing_slashes (arg_no_trailing_slash);
+
+             /* Append all of `arg' (minus any trailing slash) to `dest'.  */
+             dst_path = path_concat (dest, arg_no_trailing_slash,
+                                     &arg_in_concat);
              if (dst_path == NULL)
                xalloc_die ();