bug-findutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug #20970] Trailing slash on directory arguments breaks -name


From: Eric Blake
Subject: [bug #20970] Trailing slash on directory arguments breaks -name
Date: Tue, 04 Sep 2007 15:03:09 +0000
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6

Update of bug #20970 (project findutils):

              Depends on:                         => bugs #20688            

    _______________________________________________________

Follow-up Comment #1:

Part of me was inclined to mark this as invalid, since other implementations
that claim to implement POSIX do likewise (for example, on Solaris):

$ mkdir -p foo/bar
$ /usr/xpg4/bin/find foo -name foo
foo
$ /usr/xpg4/bin/find foo/ -name foo
$

and changing behavior would only be introducing gratuitous incompatibilities.
 But on a closer look, the wording in POSIX is:

"The primary shall evaluate as true if the basename of the filename being
examined matches pattern"

and POSIX is clear (for both basename(1) and basename(3)) that trailing
slashes are stripped when determining the basename, which means Solaris find
has the same bug.

However, remember that "foo" and "foo/" are different files when foo is a
symlink to a directory, so, modulo the -H and -L options, the output should
not strip trailing slashes for directories listed on the command line. 
However, since foo/bar and foo//bar are required to name the same file, I
would prefer reducing the amount of output, and always output foo/bar,
regardless of how many trailing slashes were given on the command line.

Therefore, I think the correct behavior is:

$ find foo
foo
foo/bar
$ find foo/
foo/
foo/bar
$ find foo/////
foo/
foo/bar
$ find foo -name foo
foo
$ find foo/ -name foo
foo
$ find foo/ -name foo/
find/find: warning: Unix filenames usually don't contain slashes (though
pathnames do).  That means that '-name foo/' will probably evaluate to false
all the time on this system.  You might find the '-wholename' test more
useful, or perhaps '-samefile'.  Alternatively, if you are using GNU grep, you
could use 'find ... -print0 | grep -FzZ foo/'.
$

As I most recently touched this area of code for bug 20688, I'll provide a
patch.

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?20970>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]