public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: "Stephen Anderson" <stephen.rhoderson@gmail.com>
To: <cygwin@cygwin.com>,	"cyg Simple" <cygsimple@gmail.com>
Subject: Re: unzip, find broken by auto handling of .exe file extension
Date: Fri, 02 Sep 2016 20:20:00 -0000	[thread overview]
Message-ID: <D6D912CDA2774E2FB30CA02A2B9467D1@skywavemobile.com> (raw)
In-Reply-To: <9c8c94a1-2df6-354e-12ed-55d9d19670ca@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3581 bytes --]

Thanks for looking at the problem.
Unfortunately not resolved...

1. As demonstrated by the provided ruby test case, it is very possible to 
have a directory and base filename be the same. Open bash and try it.

$ mkdir mything
$ touch mything.exe
$ ls mything*
mything.exe

mything:
$

2. Even if cygwin somehow prevented it (it can't), zip archives do not 
preclude the presence of a base filename with exe extension and same 
directory name.

3. The problem is not simply exe - batch files (.bat, .cmd), powershell 
(.ps1) and others are automatically picked up by cmd.exe processing, and can 
all have common base names.

4. I tried unzip -x and it does not workaround the problem. 7z remains my 
workaround and the only one I have found so far.

5. Terminating the find -path with / results in 'find: warning: -path 
testAutoExeExpansion/test/ will not match anything because it ends with /'.

6. Terminating the target with / does not help.

7. Rmdir fails with 'directory not empty'.

8. I am NOT trying to run the executable, so the globbing should NOT 
automatically be expanding 'test' to match 'test.exe'.
I would think that the only utilities that really should do that would be 
'which', 'whereis' or shell command completion (not file completion).

Attached updated test case.

sja

-----Original Message----- 
From: cyg Simple
Sent: Friday, September 02, 2016 2:40 PM
To: cygwin@cygwin.com
Subject: Re: unzip, find broken by auto handling of .exe file extension

On 9/1/2016 12:00 PM, Stephen Anderson wrote:
> I am in the process of importing zip archive contents into an SVN repo
> and have encountered problems when unzip-6.00 expands an archive
> containing an executable file in a directory that contains a
> subdirectory with the same base name as the executable. If the
> executable happens to occur after the subdirectory, unzip works, however
> if the executable is first, unzip fails with the error:
>
> checkdir error:  testAutoExeExpansion/test exists but is not directory
>                 unable to process testAutoExeExpansion/test/.
>

How can a directory and a file of the same name exist?  It can't and
because Cygwin stats the foo.exe to be foo then that is the filename
comparison.

> Luckily I am able to use 7z extract, which does not exhibit the unzip
> problem and even allows me to exclude the culprit subdirectory (which
> luckily contains nothing I am interested in).
>

Unzip has the -x option to exclude archive items.

> In the process of trying to solve this problem, I used find-4.6.0 to try
> and delete the subdirectory after extracting with 7z to no avail.
> Even preceding the path match with a type directory spec find gets
> confused (so did the svn commit BTW).
>

Did you trail the name with / for the delete?  The rmdir command should
work. You would use the -exec option with find to execute rmdir rather
than the delete function of find.

> The enclosed ruby unit test reproduces the minimal circumstances of the
> issue for both unzip and find.
> It is likely that this is a common problem somewhere in the bowels of
> file 'globbing' in cygwin only.
>

Yes and one that allows the stat of foo.exe by foo only so that it can
launch the application.  It has existed since the beginning of Cygwin
and I doubt it will ever be resolved without requiring the full file
name for executables.

-- 
cyg Simple

--
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

[-- Attachment #2: Test_ExeAutoExpand.rb --]
[-- Type: application/octet-stream, Size: 2944 bytes --]

#!/usr/bin/ruby
# $URL: http://localhost:8008/svn/Research/CygwinAutoexeExpansionProblem/Test_ExeAutoExpand.rb $ 
# $Revision: 74 $
# $Date: 2016-09-02 14:49:50 -0400 (Fri, 02 Sep 2016) $
# $Author: stephen_a $
require 'minitest/autorun'
require 'fileutils' 

# Lots of straight-forward tests, success path only.
class Test_ExeAutoExpand < Minitest::Test
  
  # Prepare common stuff for test execution.
  def setup
    # Create a hierarchy like this:
    # testAutoExeExpansion
    #    |
    #    - test.exe
    #    + test/
    #        |
    #        - test.exe
    #
    %x(rm -rf testAutoExeExpansion*)
    %x(mkdir -p testAutoExeExpansion)
    %x(mkdir -p testAutoExeExpansion/test)
    %x(touch testAutoExeExpansion/test.exe)
    %x(touch testAutoExeExpansion/test/test.exe)
  end

  # Do common stuff to wrap up tests.
  def teardown
  end

  # Check that zip/unzip with default ordering works
  # The default ordering puts directory first and seems
  # to cause no problems.
  def test_unzipDefault
    %x(zip -r testAutoExeExpansion.zip testAutoExeExpansion)
    assert_equal(0, $?.exitstatus, "zip failed!")
    %x(rm -r testAutoExeExpansion/)
    %x(unzip -ouq testAutoExeExpansion.zip)
    assert_equal(0, $?.exitstatus, "unzip failed!")
  end

  # Check that zip/unzip with exe file in archive first
  # This causes problems.
  def test_unzipExeFirst
    %x(zip testAutoExeExpansion.zip testAutoExeExpansion/test.exe)
    assert_equal(0, $?.exitstatus, "zip1 failed!")
    %x(zip -r testAutoExeExpansion.zip testAutoExeExpansion/test/)
    assert_equal(0, $?.exitstatus, "zip2 failed!")
    %x(rm -r testAutoExeExpansion/)

    %x(unzip -ouq testAutoExeExpansion.zip)
    assert_equal(0, $?.exitstatus, "unzip failed!")
  end

  # Check that zip/unzip with exe file in archive first, exclude problematic directory workaround
  # This causes problems.
  def test_unzipExeFirstExclude
    %x(zip testAutoExeExpansion.zip testAutoExeExpansion/test.exe)
    assert_equal(0, $?.exitstatus, "zip1 failed!")
    %x(zip -r testAutoExeExpansion.zip testAutoExeExpansion/test/)
    assert_equal(0, $?.exitstatus, "zip2 failed!")
    %x(rm -r testAutoExeExpansion/)

    %x(unzip -ouq testAutoExeExpansion.zip -x testAutoExeExpansion/test/ )
    assert_equal(0, $?.exitstatus, "unzip failed!")
  end

  # Check that find can locate and remove directory with co-located exe file
  # This causes problems.
  def test_findrmr
    %x(find testAutoExeExpansion -path testAutoExeExpansion/test -type d -exec rm -r {}/ \\;)
    assert_equal(0, $?.exitstatus, "find failed!")
  end

  # Check that find can locate and remove directory with co-located exe file
  # This causes problems.
  def test_findrmdir
    %x(find testAutoExeExpansion -path testAutoExeExpansion/test -type d -exec rmdir {}/ \\;)
    assert_equal(0, $?.exitstatus, "find failed!")
  end

end


[-- Attachment #3: Type: text/plain, Size: 218 bytes --]

--
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

  reply	other threads:[~2016-09-02 20:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-01 16:00 Stephen Anderson
2016-09-02 18:40 ` cyg Simple
2016-09-02 20:20   ` Stephen Anderson [this message]
2016-09-09 13:18     ` Stephen Anderson
2016-09-09 13:59       ` Nellis, Kenneth
2016-09-12 20:37         ` Stephen Anderson
2016-09-12 23:30           ` Marco Atzeri
2016-09-12 23:41             ` Stephen Anderson
2016-09-13  1:35               ` Andy Hall
2016-09-13  8:00               ` Marco Atzeri

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=D6D912CDA2774E2FB30CA02A2B9467D1@skywavemobile.com \
    --to=stephen.rhoderson@gmail.com \
    --cc=cygsimple@gmail.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).