On Thu, 15 Mar 2007, Otto Moerbeek wrote:

> On Thu, 15 Mar 2007, Han Boetes wrote:
> 
> > Otto Moerbeek wrote:
> > > Hmm, can you instrument /usr/libexec/locate.updatedb with a 
> > >
> > >   .... tee /tmp/myflist |
> > >
> > > on line 101 to see the filelist it actualy builds?
> > 
> > Sure, I just did that and examined /tmp/myflist and it looks
> > perfectly normal.
> 
> Can you send it to me so I can process it here and see if it creates a
> corrupted DB? 

I see the problem. The problem occurs if top bigrams contain spaces.
These are not handled correctly by awk. We'll have to use a field
separator that can not be in a bigram. A tab is well suited, AFAKS.

Try this.

        -Otto

Index: bigram/locate.bigram.c
===================================================================
RCS file: /cvs/src/usr.bin/locate/bigram/locate.bigram.c,v
retrieving revision 1.10
diff -u -p -r1.10 locate.bigram.c
--- bigram/locate.bigram.c      29 Sep 2003 16:03:16 -0000      1.10
+++ bigram/locate.bigram.c      15 Mar 2007 22:39:30 -0000
@@ -106,7 +106,7 @@ main(void)
        for (i = ASCII_MIN; i <= ASCII_MAX; i++)
                for (j = ASCII_MIN; j <= ASCII_MAX; j++)
                        if (bigram[i][j] != 0)
-                               (void)printf("%4u %c%c\n", bigram[i][j], i, j);
+                               (void)printf("%4u\t%c%c\n", bigram[i][j], i, j);
 
        exit(0);
 }
Index: code/locate.code.c
===================================================================
RCS file: /cvs/src/usr.bin/locate/code/locate.code.c,v
retrieving revision 1.14
diff -u -p -r1.14 locate.code.c
--- code/locate.code.c  19 Feb 2007 20:01:12 -0000      1.14
+++ code/locate.code.c  15 Mar 2007 09:25:18 -0000
@@ -149,6 +149,9 @@ main(int argc, char *argv[])
        if (fgets(bigrams, sizeof(bigrams), fp) == NULL)
                err(1, "fgets");
 
+       if (strlen(bigrams) != BGBUFSIZE)
+               errx(1, "bigram array too small to build db, index more files");
+
        if (fputs(bigrams, stdout) == EOF)
                err(1, "stdout");
        (void)fclose(fp);
Index: locate/mklocatedb.sh
===================================================================
RCS file: /cvs/src/usr.bin/locate/locate/mklocatedb.sh,v
retrieving revision 1.12
diff -u -p -r1.12 mklocatedb.sh
--- locate/mklocatedb.sh        29 Jun 2003 21:59:28 -0000      1.12
+++ locate/mklocatedb.sh        15 Mar 2007 22:40:27 -0000
@@ -68,7 +68,7 @@ trap 'rm -f $bigrams $filelist' 0 1 2 3 
 
 if $sortcmd $sortopt > $filelist; then
         $bigram < $filelist | $sort -nr | 
-                awk 'BEGIN { ORS = "" } NR <= 128 { print $2 }' > $bigrams &&
+                awk -Ft 'BEGIN { ORS = "" } NR <= 128 { print $2 }' > $bigrams 
&&
         $code $bigrams < $filelist 
 else
         echo "`basename $0`: cannot build locate database" >&2

Reply via email to