bug-fileutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bug in mv (fileutils) 4.1


From: Jim Meyering
Subject: Re: bug in mv (fileutils) 4.1
Date: Sun, 17 Nov 2002 10:41:17 +0100

>       export POSIXLY_CORRECT=1
>       mkdir mv_test
>       cd mv_test
>       mkdir a c
>       ln -s a b
>       mv -v b/ c
>       alias mv
>       which mv
>
> I expected, as is written, that the directory a will be moved into
> directory c (the symbolic link b to directory a will be dereferenced),
> but the link b has been moved. There is no alias for mv, mv resides in
> /bin.

Whoops.
I forgot a minor detail :-)
Your report exposed a bug in mv.c:

mv (coreutils-4.5.3) mistakenly strips trailing slashes
from the SOURCE name in some cases.  Here's a fix:

Index: mv.c
===================================================================
RCS file: /fetish/cu/src/mv.c,v
retrieving revision 1.140
diff -u -p -u -p -r1.140 mv.c
--- mv.c        31 Aug 2002 08:52:10 -0000      1.140
+++ mv.c        17 Nov 2002 09:34:18 -0000
@@ -284,14 +284,11 @@ movefile (char *source, char *dest, int
   if (dest_is_dir || (dest_had_trailing_slash && !is_real_dir (source)))
     {
       /* DEST is a directory; build full target filename. */
-      char *src_basename;
-      char *new_dest;
-
-      strip_trailing_slashes (source);
-      src_basename = base_name (source);
-      new_dest = path_concat (dest, src_basename, NULL);
+      char const *src_basename = base_name (source);
+      char *new_dest = path_concat (dest, src_basename, NULL);
       if (new_dest == NULL)
        xalloc_die ();
+      strip_trailing_slashes (new_dest);
       fail = do_move (source, new_dest, x);
       free (new_dest);
     }

Maybe now, my preceding message makes more sense,
since with the modified mv, your example evokes this diagnostic:

  $ ./mv b/ c
  ./mv: cannot move `b/' to `c/b': Not a directory
  [Exit 1]

Thanks again,
Jim

BTW, the latest sources are here:

  ftp://alpha.gnu.org/gnu/fetish/coreutils-4.5.3.tar.gz




reply via email to

[Prev in Thread] Current Thread [Next in Thread]