Subject: Bug in mv (coreutils 6.10)
From: Keith Thompson <[email-masked]>
To: [email-masked]
Cc: Keith Thompson <[email-masked]>
Date: Wed, 26 Mar 2008 09:56:42 -0700
List-Id: <cygwin.cygwin.com>

When I want to use "mv" to move a file into a directory, I've
habitually append "/." to the directory name, so that the command
will fail if the name actually refers to a file or if it doesn't exist.

(I used to use just "/", but Solaris for some supremely odd reason
allows a file "foo" to be referred to as "foo/", so I've cultivated
the habit of using "/.".)

I've recently found that the "mv" command, if given a second argument
of "nosuchdir/.", if "nosuchdir" doesn't exist, treats it as a file
name.  I don't know whether this is specific to Cygwin or a bug in
the current GNU coreutils.

Two additional data points: The problem does not occur with coreutils
5.97 under Ubuntu 7.10 or with coreutils 6.9 under Solaris 9.  And I
haven't noticed it under Cygwin until fairly recently (though I could
have missed it).

Here's a shell script that demonstrates the problem:
================================================================
#!/bin/sh

try() {
    echo "% $@"
    "$@"
    status=$?
    if [ $status -ne 0 ] ; then
        echo exit $status
    fi
}

tmpdir=$HOME/cygwin-mv-bug
if [ -d $tmpdir ] ; then
    try rm -rf $tmpdir
fi

try mkdir $tmpdir
try cd $tmpdir

try touch foo
echo "... Directory should contain only 'foo'"
try ls -l
echo "... The cp command should fail"
try cp foo nosuchdir/.
try ls -l
echo "... The mv command should also fail"
try mv foo nosuchdir/.
echo "... but it succeeds, renaming 'foo' to 'nosuchdir'"
try ls -l
try cp --version
try mv --version

try cd $HOME
try rm -rf $tmpdir
================================================================

and the output I get:
================================================================
% mkdir /home/keithomp/cygwin-mv-bug
% cd /home/keithomp/cygwin-mv-bug
% touch foo
... Directory should contain only 'foo'
% ls -l
total 0
-rw-r--r-- 1 keithomp mkgroup-l-d 0 Mar 26 09:53 foo
... The cp command should fail
% cp foo nosuchdir/.
cp: cannot create regular file `nosuchdir/.': Is a directory
exit 1
% ls -l
total 0
-rw-r--r-- 1 keithomp mkgroup-l-d 0 Mar 26 09:53 foo
... The mv command should also fail
% mv foo nosuchdir/.
... but it succeeds, renaming 'foo' to 'nosuchdir'
% ls -l
total 0
-rw-r--r-- 1 keithomp mkgroup-l-d 0 Mar 26 09:53 nosuchdir
% cp --version
cp (GNU coreutils) 6.10
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Torbjorn Granlund, David MacKenzie, and Jim Meyering.
% mv --version
mv (GNU coreutils) 6.10
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Parker, David MacKenzie, and Jim Meyering.
% cd /home/keithomp
% rm -rf /home/keithomp/cygwin-mv-bug
================================================================

-- 
Keith Thompson (The_Other_Keith) [email-masked]  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/