delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2010/06/09/12:29:20

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=2.0 required=5.0 tests=AWL,BAYES_50,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,T_TO_NO_BRKTS_FREEMAIL
X-Spam-Check-By: sourceware.org
Date: Wed, 9 Jun 2010 18:28:38 +0200
From: Michael Ludwig <milu71 AT gmx DOT de>
To: cygwin AT cygwin DOT com
Subject: Re: 'cp' utility bug when <dest-name>.exe file exist.
Message-ID: <20100609162838.GF5096@wladimir>
Mail-Followup-To: cygwin AT cygwin DOT com
References: <hulhlm$ro4$1 AT dough DOT gmane DOT org>
Mime-Version: 1.0
In-Reply-To: <hulhlm$ro4$1@dough.gmane.org>
User-Agent: Mutt/1.4.2.2i
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT 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

Oleksandr Gavenko schrieb am 08.06.2010 um 16:47 (+0300):
>   $ touch my.exe
>   $ touch some-file
>   $ cp some-file my
> cp: cannot create regular file `my': File exists
>   $ cp -f some-file my
> cp: cannot create regular file `my': File exists
> 
> Same happen ever in cmd.exe so this is not 'bash' fault.

Here's a test script for further amusement. Bottom line is that cp and
shell redirection do quite some unexpected and uncalled-for clobbering.
That should probably be fixed.

          \,,,/
          (o o)
------oOOo-(_)-oOOo------
#!/bin/bash --verbose
dirname=/tmp/tt$(date +%s)
mkdir $dirname && cd $dirname || exit $?
touch eins.exe          # create eins.exe
ls -l
echo 1 > eins           # clobbers eins.exe
ls -l
echo 22 > zwei          # create zwei
cp zwei eins            # refuses to create file (the OP's report)
ls -l
mv eins.exe eins        # rename eins.exe to eins
cp zwei eins            # overwrites eins as expected
ls -l
rm eins                 # delete eins
echo 1 > eins.exe       # recreate eins.exe
ls -l
mv zwei eins            # creates eins, does not clobber eins.exe
ls -l
mv eins zwei            # rename it back to zwei
echo 222 > ../zwei.exe  # create file with extension
cp ../zwei.exe .        # clobbers file without exe extension
ls -l
echo 2222 > zwei        # clobbers file with exe extension
ls -l
cp ../zwei.exe zwei     # refuses to create file
ls -l
mv ../zwei.exe zwei     # creates zwei, does not clobber zwei.exe
ls -l
cp ../zwei .            # clobbers file with exe extension
ls -l
-------------------------

As for the general question, Windows and UNIX are very different, and
Cygwin does a fantastic exe-magic job of bringing the two together, a
great treat for those who want to, or have to, use both systems.

Thanks for that!
-- 
Michael Ludwig

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

- Raw text -


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