This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: tar deletes .exe files on extraction

On Aug  8 03:16, Steven Hartland wrote:
> If you extract a tar.gz file with an executable file and
> an excitable file of the same name but with the .exe extension
> on extract the .exe file is inexplicably deleted.
> e.g.
> tar -xvzf test.tar.gz
> mydir/myexe.exe
> mydir/myexe
> ls myddir
> myexe

Yeah, that's to be expected.

Cygwin always handled the .exe suffix transparently in terms of stat(2)
calls, but Cygwin 1.7 also handles them transparently in terms of
open(2) and any other call.  Therefore, if a file foo.exe exists, and an
application calls stat("foo"), it will get told that, yes, "foo" exists.
That's a basic component of being able to call foo.exe from bash by just
typing foo<enter>.  POSIX systems just don't have the .exe suffix for

AFAICS from the strace, tar unpacks mydir/myexe.exe, then it goes ahead
to unpack mydir/myexe.  It tries to open the file with O_CREAT | O_EXCL
flags.  Since the file exists from Cygwin's POV, open(2) returns -1 with
errno set to EEXIST.  If that happens tar calls unlink("mydir/myexe")
and the unlink() call succeeds, since, as mentioned above, the .exe
suffix is transparent to every filesystem call.  Therefore,
unlink("mydir/myexe") actually deletes "mydir/myexe.exe".  Then tar
proceeds to unpack "mydir/myexe".

Keep in mind that myexe and myexe.exe are for all practical purposes the
same file from Cygwin's point of view.  On a POSIX system you just don't
have a "normal" file called myexe in the same directory as an executable
"myexe", since that is the same file anyway, and the .exe suffix is just
an annoying Windowism.  On Cygwin, you should avoid having a file "foo"
and a file "foo.exe" in the same directory at all cost to avoid
puzzeling POSIX borderline behaviour like this.  What you do is
essentially in the "not supported" class of problems.

Fortunately for you there's a workaround.  If the order of the files in
the tar archive is reversed, both files are unpacked.  Or, unpack
mydir/myexe.exe explicitely afterwards.  The reason that this works is
that Cygwin does not check for a file "foo", if the name of the file is
explicitely given as "foo.exe".


Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]