Subject: locate(1) (was Re: CVS commit: basesrc)
To: None <source-changes@netbsd.org, tech-userlevel@netbsd.org>
From: ITOH Yasufumi <itohy@netbsd.org>
List: tech-userlevel
Date: 03/08/2000 09:08:55
In article <200003071430.XAA01792@srapc342.sra.co.jp>
soda@sra.co.jp writes:
> > So, there are many aspects. :-(
>
> In my system, MFS /tmp (32MB) cannot hold temporary files for locate
> database, but /var/tmp (150MB) can.
The temporary storage is used by sort(1), which sorts the entries
of each directories.
If the find(1) could sort dir entries (as FreeBSD's; see patch below)
and if the update script used the funnction, such are large temporary
area would not be required.
By the way, does anyone have ideas to make locate(1) 8-bit through?
Current implementation is not even 7-bit through....
--
ITOH, Yasufumi <itohy@netbsd.org>
diff -uF^[a-zA-Z_][a-z A-Z0-9_]*(.*[^;]$ usr.bin/find/main.c.orig usr.bin/find/main.c
--- usr.bin/find/main.c.orig Tue Jun 29 09:06:21 1999
+++ usr.bin/find/main.c Fri Oct 15 13:36:00 1999
@@ -67,6 +67,7 @@ __RCSID("$NetBSD: main.c,v 1.11 1999/04/
int isdeprecated; /* using deprecated syntax */
int isdepth; /* do directories on post-order visit */
int isoutput; /* user specified output operator */
+int issort; /* sort directory entries */
int isxargs; /* don't permit xargs delimiting chars */
int main __P((int, char **));
@@ -86,7 +87,7 @@ main(argc, argv)
p = start = alloca(argc * sizeof (char *));
ftsoptions = FTS_NOSTAT | FTS_PHYSICAL;
- while ((ch = getopt(argc, argv, "HLPXdf:hx")) != EOF)
+ while ((ch = getopt(argc, argv, "HLPXdf:hsx")) != EOF)
switch(ch) {
case 'H':
ftsoptions |= FTS_COMFOLLOW;
@@ -115,6 +116,9 @@ main(argc, argv)
ftsoptions &= ~FTS_PHYSICAL;
ftsoptions |= FTS_LOGICAL;
break;
+ case 's':
+ issort = 1;
+ break;
case 'x':
ftsoptions |= FTS_XDEV;
break;
@@ -123,7 +127,7 @@ main(argc, argv)
break;
}
- argc -= optind;
+ argc -= optind;
argv += optind;
/*
diff -uF^[a-zA-Z_][a-z A-Z0-9_]*(.*[^;]$ usr.bin/find/find.c.orig usr.bin/find/find.c
--- usr.bin/find/find.c.orig Sun Feb 22 21:13:10 1998
+++ usr.bin/find/find.c Mon Oct 11 13:50:39 1999
@@ -57,6 +57,8 @@ __RCSID("$NetBSD: find.c,v 1.11 1998/02/
#include "find.h"
+static int ftscompare __P((const FTSENT **, const FTSENT **));
+
/*
* find_formplan --
* process the command line and create a "plan" corresponding to the
@@ -94,7 +96,7 @@ find_formplan(argv)
tail = new;
}
}
-
+
/*
* if the user didn't specify one of -print, -ok or -exec, then -print
* is assumed so we bracket the current expression with parens, if
@@ -116,7 +118,7 @@ find_formplan(argv)
tail = new;
}
}
-
+
/*
* the command line has been completely processed into a search plan
* except for the (, ), !, and -o operators. Rearrange the plan so
@@ -145,7 +147,14 @@ find_formplan(argv)
plan = or_squish(plan); /* -o's */
return (plan);
}
-
+
+static int
+ftscompare(e1, e2)
+ const FTSENT **e1, **e2;
+{
+ return strcmp((*e1)->fts_name, (*e2)->fts_name);
+}
+
FTS *tree; /* pointer to top of FTS hierarchy */
/*
@@ -161,8 +170,8 @@ find_execute(plan, paths)
register FTSENT *entry;
PLAN *p;
int rval;
-
- if (!(tree = fts_open(paths, ftsoptions, NULL)))
+
+ if (!(tree = fts_open(paths, ftsoptions, issort ? ftscompare : NULL)))
err(1, "ftsopen");
for (rval = 0; (entry = fts_read(tree)) != NULL; ) {
@@ -195,7 +204,7 @@ find_execute(plan, paths)
rval = 1;
continue;
}
-
+
/*
* Call all the functions in the execution plan until one is
* false or all have been executed. This is where we do all
diff -u usr.bin/find/extern.h.orig usr.bin/find/extern.h
--- usr.bin/find/extern.h.orig Wed Jul 21 10:22:47 1999
+++ usr.bin/find/extern.h Mon Oct 11 13:45:20 1999
@@ -87,4 +87,4 @@
PLAN *c_or __P((char ***, int));
PLAN *c_null __P((char ***, int));
-extern int ftsoptions, isdeprecated, isdepth, isoutput, isxargs;
+extern int ftsoptions, isdeprecated, isdepth, isoutput, issort, isxargs;