[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Patch] locate --non-existing (-E): New option.
From: |
Bas van Gompel |
Subject: |
[Patch] locate --non-existing (-E): New option. |
Date: |
Tue, 8 Mar 2005 01:54:43 +0100 (MET) |
User-agent: |
slrn/0.9.8.1 (Win32) Hamster/2.0.6.0 Korrnews/4.2 |
Hallo,
Here is a patch which implements a ``--non-existing'' (``-E'') option
on locate. It's effect is the inverse of ``--existing'' (``-e'').
Along the way I renamed visit_exists_[no]follow to
visit_existing_[no]follow for consistency, and fixed a a few typos in
the description of --nofollow (``treat broken symbolic links /count/
as if they were exi/s/ting'').
A possible ChangeLog-entry:
2005-03-08 Bas van Gompel <address@hidden>
*doc/find.texi: Document locate --non-existing (-E).
*locate/locate.1: Ditto.
*locate/locate.c: Implement --non-existing (-E).
diff -Ndrupb curr/findutils/doc/find.texi mine2/findutils/doc/find.texi
--- findutils/doc/find.texi 2005-03-01 21:19:26.000000000 +0100
+++ findutils/doc/find.texi 2005-03-08 00:58:56.000000000 +0100
@@ -2673,17 +2673,26 @@ down the program a lot, if there are man
The way in which broken symbolic links are treated is affected by the
@samp{-L}, @samp{-P} and @samp{-H} options.
address@hidden --non-existing
address@hidden -E
+Only print out such names which currently do not exist (instead of such
+names which existed when the database was created).
+Note that this may slow down the program a lot, if there are many matches
+in the database.
+The way in which broken symbolic links are treated is affected by the
address@hidden, @samp{-P} and @samp{-H} options.
+
@item --follow
@itemx -L
-If testing for the existence of files (with the @samp{-e} option),
-omit broken symbolic links. This is the default.
+If testing for the existence of files (with the @samp{-e} or @samp(-E)
options),
+consider broken symbolic links to be non-existing. This is the default.
@item --nofollow
@itemx -P
@itemx -H
-If testing for the existence of files (with the @samp{-e} option),
-treat broken symbolic links count as if they were exiting files. The
+If testing for the existence of files (with the @samp{-e} or @samp(-E)
options),
+treat broken symbolic links as if they were existing files. The
@samp{-H} form of this option is provided purely for similarity with
@code{find}; the use of @samp{-P} is recommended over @samp{-H}.
diff -Ndrupb curr/findutils/locate/locate.1 mine2/findutils/locate/locate.1
--- findutils/locate/locate.1 2005-01-29 02:27:24.000000000 +0100
+++ findutils/locate/locate.1 2005-03-08 01:01:56.000000000 +0100
@@ -3,10 +3,11 @@
locate \- list files in databases that match a pattern
.SH SYNOPSIS
.B locate
-[\-d path | \-\-database=path] [\-e | \-\-existing] [\-i | \-\-ignore-case]
-[\-0 | \-\-null] [\-c | \-\-count] [\-w | \-\-wholename] [\-b | \-\-basename]
-[\-l N | \-\-limit=N] [\-S | \-\-statistics] [\-r | \-\-regex ]
-[\-P | \-H | \-\-nofollow] [\-L | \-\-follow] [\-\-version] [\-\-help]
pattern...
+[\-d path | \-\-database=path] [\-e | \-E | \-\-[non\-]existing] [\-i
+| \-\-ignore-case] [\-0 | \-\-null] [\-c | \-\-count] [\-w | \-\-wholename]
+|\-b | \-\-basename] [\-l N | \-\-limit=N] [\-S | \-\-statistics] [\-r
+| \-\-regex ] [\-P | \-H | \-\-nofollow] [\-L | \-\-follow] [\-\-version]
+[\-\-help] pattern...
.SH DESCRIPTION
This manual page
documents the GNU version of
@@ -80,13 +81,19 @@ please note that it is possible for the
.B locate
has checked that it exists, but before you use it.
.TP
+.I "\-E, \-\-non\-existing"
+Only print out such names that currently do not exist (instead of such names
+that existed when the database was created).
+Note that this may slow down the program a lot, if there are many matches
+in the database.
+.TP
.I "\-L, \-\-follow"
-If testing for the existence of files (with the \-e option), omit
-broken symbolic links. This is the default.
+If testing for the existence of files (with the \-e or \-E options),
+consider broken symbolic links to be non-existing. This is the default.
.TP
.I "\-P, \-H, \-\-nofollow"
-If testing for the existence of files (with the \-e option), treat
-broken symbolic links count as if they were exiting files. The \-H
+If testing for the existence of files (with the \-e or \-E options), treat
+broken symbolic links as if they were existing files. The \-H
form of this option is provided purely for similarity with
.BR find ;
the use of \-P is recommended over \-H.
diff -Ndrupb curr/findutils/locate/locate.c mine2/findutils/locate/locate.c
--- findutils/locate/locate.c 2005-03-05 20:11:58.000000000 +0100
+++ findutils/locate/locate.c 2005-03-06 23:38:58.000000000 +0100
@@ -331,7 +331,7 @@ visit_justprint(const char *munged_filen
}
static int
-visit_exists_follow(const char *munged_filename,
+visit_existing_follow(const char *munged_filename,
const char *original_filename, void *context)
{
struct stat st;
@@ -354,7 +354,30 @@ visit_exists_follow(const char *munged_f
}
static int
-visit_exists_nofollow(const char *munged_filename,
+visit_non_existing_follow(const char *munged_filename,
+ const char *original_filename, void *context)
+{
+ struct stat st;
+ (void) context;
+ (void) munged_filename;
+
+ /* munged_filename has been converted in some way (to lower case,
+ * or is just the base name of the file), and original_filename has not.
+ * Hence only original_filename is still actually the name of the file
+ * whose existence we would need to check.
+ */
+ if (stat(original_filename, &st) == 0)
+ {
+ return VISIT_REJECTED;
+ }
+ else
+ {
+ return VISIT_CONTINUE;
+ }
+}
+
+static int
+visit_existing_nofollow(const char *munged_filename,
const char *original_filename, void *context)
{
struct stat st;
@@ -377,6 +400,29 @@ visit_exists_nofollow(const char *munged
}
static int
+visit_non_existing_nofollow(const char *munged_filename,
+ const char *original_filename, void *context)
+{
+ struct stat st;
+ (void) context;
+ (void) munged_filename;
+
+ /* munged_filename has been converted in some way (to lower case,
+ * or is just the base name of the file), and original_filename has not.
+ * Hence only original_filename is still actually the name of the file
+ * whose existence we would need to check.
+ */
+ if (lstat(original_filename, &st) == 0)
+ {
+ return VISIT_REJECTED;
+ }
+ else
+ {
+ return VISIT_CONTINUE;
+ }
+}
+
+static int
visit_substring_match_nocasefold(const char *munged_filename, const char
*original_filename, void *context)
{
const char *pattern = context;
@@ -611,20 +657,20 @@ new_locate (char *pathpart,
}
}
- /* We add visit_exists_*() as late as possible to reduce the
+ /* We add visit_existing_*() as late as possible to reduce the
* number of stat() calls.
*/
- if (check_existence)
- {
- visitfunc f;
+ if (check_existence==1)
if (follow_symlinks)
- f = visit_exists_follow;
+ add_visitor(visit_existing_follow, NULL);
else
- f = visit_exists_nofollow;
-
- add_visitor(f, NULL);
- }
+ add_visitor(visit_existing_nofollow, NULL);
+ if (check_existence==2)
+ if (follow_symlinks)
+ add_visitor(visit_non_existing_follow, NULL);
+ else
+ add_visitor(visit_non_existing_nofollow, NULL);
if (enable_print)
add_visitor(visit_justprint, NULL);
@@ -778,7 +824,7 @@ usage (stream)
FILE *stream;
{
fprintf (stream, _("\
-Usage: %s [-d path | --database=path] [-e | --existing]\n\
+Usage: %s [-d path | --database=path] [-e | -E | --[non-]existing]\n\
[-i | --ignore-case] [-w | --wholename] [-b | --basename] \n\
[--limit=N | -l N] [-S | --statistics] [-0 | --null] [-c | --count]\n\
[-P | -H | --nofollow] [-L | --follow] [-m | --mmap ] [ -s | --stdio ]\n\
@@ -791,6 +837,7 @@ static struct option const longopts[] =
{
{"database", required_argument, NULL, 'd'},
{"existing", no_argument, NULL, 'e'},
+ {"non-existing", no_argument, NULL, 'E'},
{"ignore-case", no_argument, NULL, 'i'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'v'},
@@ -841,7 +888,7 @@ main (argc, argv)
check_existence = 0;
- while ((optc = getopt_long (argc, argv, "bcd:eil:rsm0SwHPL", longopts, (int
*) 0)) != -1)
+ while ((optc = getopt_long (argc, argv, "bcd:eEil:rsm0SwHPL", longopts, (int
*) 0)) != -1)
switch (optc)
{
case '0':
@@ -865,6 +912,10 @@ main (argc, argv)
check_existence = 1;
break;
+ case 'E':
+ check_existence = 2;
+ break;
+
case 'i':
ignore_case = 1;
break;
L8r,
Buzz.
--
) | | ---/ ---/ Yes, this | This message consists of true | I do not
-- | | / / really is | and false bits entirely. | mail for
) | | / / a 72 by 4 +-------------------------------+ any1 but
-- \--| /--- /--- .sigfile. | |perl -pe "s.u(z)\1.as." | me. 4^re
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Patch] locate --non-existing (-E): New option.,
Bas van Gompel <=