bug-findutils
[Top][All Lists]
Advanced

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

Re: Glob fix in locate.c


From: Russell Shaw
Subject: Re: Glob fix in locate.c
Date: Sun, 13 Jun 2004 15:50:51 +1000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040122 Debian/1.6-1

Andreas Metzler wrote:
On 2004-06-12 Russell Shaw <address@hidden> wrote:
[...]

I found that locate tries to match against full path
names.

This is a feature, not a bug.

Why? How is locate usually used? Isn't the purpose of locate
for finding known file-name patterns that have an unknown path?

This patch makes it match against the path with
leading directories removed.

[...]

A proper patch would need to make this behavior changeable with a
commandline option.
       cu and- this just my personal opinion -dreas

Without the patch, /usr/bin/locate gdk-2.0.pc
gives:

  /usr/lib/pkgconfig/gdk-2.0.pc
  /usr/local/lib/pkgconfig/gdk-2.0.pc
  /usr/share/doc/gdk-2.0.pc
  /usr/share/doc/gdk-2.0.pc.in

while /usr/bin/locate g*.pc
gives nothing.

Now gdk-2.0.pc obviously doesn't match this string:
/usr/lib/pkgconfig/gdk-2.0.pc, it only matches the
filename at the end of the path.

So by logical inference, g*.pc should also not match
the string: /usr/lib/pkgconfig/gdk-2.0.pc, but only the
filename at the end.

Therefore, how can it not be a bug that: locate g*.pc
returns nothing?

Anyway, i found that with my patch, locate is 10 times
more useful to me than ever before, and is how it should
work;)

BTW, my last patch was incomplete. It should be:


diff -apru findutils-4.1.20/locate/locate.c findutils-4.1.20-new/locate/locate.c
--- findutils-4.1.20/locate/locate.c    Mon May 26 23:39:54 2003
+++ findutils-4.1.20-new/locate/locate.c        Sun Jun 13 15:44:14 2004
@@ -409,7 +409,7 @@ locate (pathpart, dbfile, ignore_case)
                    /* Success on the fast match.  Compare the whole pattern
                       if it contains globbing characters.  */
                    prev_fast_match = true;
- if (globflag == false || fnmatch (pathpart, path, FNM_CASEFOLD) == 0) + if (globflag == false || fnmatch (pathpart, basename(path), FNM_CASEFOLD) == 0)
                      {
                        if (!check_existence || stat(path, &st) == 0)
                          {
@@ -438,7 +438,7 @@ locate (pathpart, dbfile, ignore_case)
                /* Success on the fast match.  Compare the whole pattern
                   if it contains globbing characters.  */
                prev_fast_match = true;
-               if (globflag == false || fnmatch (pathpart, path,
+               if (globflag == false || fnmatch (pathpart, basename(path),
                                                  0) == 0)
                  {
                    if (!check_existence || stat(path, &st) == 0)





reply via email to

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