[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: coreutils 5.3.0: cp --parents broken
From: |
Jim Meyering |
Subject: |
Re: coreutils 5.3.0: cp --parents broken |
Date: |
Tue, 25 Jan 2005 10:29:43 +0100 |
Andreas Schwab <address@hidden> wrote:
> Jim Meyering <address@hidden> writes:
>> Andreas Schwab <address@hidden> wrote:
>>> $ ./cp --parents /bin/cp /tmp
>>> ./cp: failed to get attributes of `bin': No such file or directory
>>
>> Thanks for the report.
>> I can't reproduce that:
>
> Please make sure that /tmp/bin does not exist.
Ahh...
I should have known better.
I *can* reproduce it.
Here's the fix.
Thanks again for reporting that!
I'll add a test of `cp --parents' to exercise this.
2005-01-25 Jim Meyering <address@hidden>
* path-concat.c (path_concat): Set *BASE_IN_RESULT
properly when ABASE is an absolute file name.
Correct the description of this function.
Include <assert.h>.
Add an assertion and a test driver.
This fixes a bug introduced on 2004-07-02.
Andreas Schwab reported the resulting failure in cp --parents:
http://lists.gnu.org/archive/html/bug-coreutils/2005-01/msg00130.html
Index: lib/path-concat.c
===================================================================
RCS file: /fetish/cu/lib/path-concat.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -p -u -r1.21 -r1.22
--- path-concat.c 5 Jul 2004 08:41:13 -0000 1.21
+++ path-concat.c 25 Jan 2005 09:07:49 -0000 1.22
@@ -1,6 +1,6 @@
/* path-concat.c -- concatenate two arbitrary pathnames
- Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free
+ Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
Free
Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
@@ -22,6 +22,7 @@
#if HAVE_CONFIG_H
# include <config.h>
#endif
+# include <assert.h>
/* Specification. */
#include "path-concat.h"
@@ -54,7 +55,7 @@ longest_relative_suffix (char const *f)
Arrange for a directory separator if necessary between DIR and BASE
in the result, removing any redundant separators.
In any case, if BASE_IN_RESULT is non-NULL, set
- *BASE_IN_RESULT to point to the copy of BASE in the returned
+ *BASE_IN_RESULT to point to the copy of ABASE in the returned
concatenation.
Report an error if memory is exhausted. */
@@ -78,10 +79,49 @@ path_concat (char const *dir, char const
p += needs_separator;
if (base_in_result)
- *base_in_result = p;
+ *base_in_result = p - IS_ABSOLUTE_FILE_NAME (abase);
p = mempcpy (p, base, baselen);
*p = '\0';
+ assert (!base_in_result
+ || strcmp (*base_in_result, abase) == 0);
+
return p_concat;
}
+
+#ifdef TEST_PATH_CONCAT
+#include <stdlib.h>
+#include <stdio.h>
+int
+main ()
+{
+ static char const *const tests[][3] =
+ {
+ {"a", "b", "a/b"},
+ {"a/", "b", "a/b"},
+ {"a/", "/b", "a/b"},
+ {"a", "/b", "a/b"},
+
+ {"/", "b", "/b"},
+ {"/", "/b", "/b"},
+ {"/", "/", "/"},
+ {"a", "/", "a/"}, /* this might deserve a diagnostic */
+ {"/a", "/", "/a/"}, /* this might deserve a diagnostic */
+ };
+ size_t i;
+ bool fail = false;
+ for (i = 0; i < sizeof tests / sizeof tests[0]; i++)
+ {
+ char *base_in_result;
+ char const *const *t = tests[i];
+ char *res = path_concat (t[0], t[1], &base_in_result);
+ if (strcmp (res, t[2]) != 0)
+ {
+ printf ("got %s, expected %s\n", res, t[2]);
+ fail = true;
+ }
+ }
+ exit (fail ? EXIT_FAILURE : EXIT_SUCCESS);
+}
+#endif