delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2008/03/26/11:57:23

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Date: Wed, 26 Mar 2008 09:56:42 -0700
From: Keith Thompson <kst AT mib DOT org>
To: cygwin AT cygwin DOT com
Cc: Keith Thompson <kst AT mib DOT org>
Message-ID: <20080326165642.GA29317@nuthaus.mib.org>
Mime-Version: 1.0
User-Agent: Mutt/1.4.1i
Subject: Bug in mv (coreutils 6.10)
X-SA-Exim-Connect-IP: <locally generated>
X-SA-Exim-Mail-From: kst AT mib DOT org
X-SA-Exim-Version: 4.2.1 (built Thu, 02 Aug 2007 20:57:52 -0700)
X-SA-Exim-Scanned: Yes (on nuthaus.mib.org)
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT 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) kst AT mib DOT org  <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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019