Better help message if locate database does not exists
PR: 211501 Reported by: Oliver Peter Reviewed by: Pau Amma Differential Revision: https://reviews.freebsd.org/D34243
This commit is contained in:
parent
09d0a0fbe8
commit
93885bb041
@ -124,6 +124,8 @@ extern int getwf(FILE *);
|
||||
extern u_char *tolower_word(u_char *);
|
||||
extern int check_bigram_char(int);
|
||||
extern char *patprep(char *);
|
||||
extern void rebuild_message(char *db);
|
||||
extern int check_size(char *db);
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
@ -216,7 +218,6 @@ main(int argc, char **argv)
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Arguments:
|
||||
* db database
|
||||
@ -235,8 +236,16 @@ search_fopen(char *db, char **s)
|
||||
*(s+1) = NULL;
|
||||
}
|
||||
}
|
||||
else if ((fp = fopen(db, "r")) == NULL)
|
||||
err(1, "`%s'", db);
|
||||
else {
|
||||
if (!check_size(db))
|
||||
exit(1);
|
||||
|
||||
if ((fp = fopen(db, "r")) == NULL) {
|
||||
warn("`%s'", db);
|
||||
rebuild_message(db);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/* count only chars or lines */
|
||||
if (f_statistic) {
|
||||
@ -261,6 +270,7 @@ search_fopen(char *db, char **s)
|
||||
}
|
||||
|
||||
#ifdef MMAP
|
||||
|
||||
/*
|
||||
* Arguments:
|
||||
* db database
|
||||
@ -273,14 +283,20 @@ search_mmap(char *db, char **s)
|
||||
int fd;
|
||||
caddr_t p;
|
||||
off_t len;
|
||||
if ((fd = open(db, O_RDONLY)) == -1 ||
|
||||
fstat(fd, &sb) == -1)
|
||||
err(1, "`%s'", db);
|
||||
|
||||
if (!check_size(db))
|
||||
exit(1);
|
||||
|
||||
if (stat(db, &sb) == -1)
|
||||
err(1, "stat");
|
||||
|
||||
len = sb.st_size;
|
||||
if (len < (2*NBG))
|
||||
errx(1,
|
||||
"database too small: %s\nRun /usr/libexec/locate.updatedb",
|
||||
db);
|
||||
|
||||
if ((fd = open(db, O_RDONLY)) == -1) {
|
||||
warn("%s", db);
|
||||
rebuild_message(db);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ((p = mmap((caddr_t)0, (size_t)len,
|
||||
PROT_READ, MAP_SHARED,
|
||||
|
@ -41,8 +41,10 @@
|
||||
#include <err.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "locate.h"
|
||||
#include "pathnames.h"
|
||||
|
||||
char **colon(char **, char*, char*);
|
||||
char *patprep(char *);
|
||||
@ -268,3 +270,37 @@ getwf(fp)
|
||||
}
|
||||
return(word);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
rebuild_message(char *db)
|
||||
{
|
||||
/* only for the default locate database */
|
||||
if (strcmp(_PATH_FCODES, db) == 0) {
|
||||
fprintf(stderr, "\nTo create a new database, please run the following command as root:\n\n");
|
||||
fprintf(stderr, " /etc/periodic/weekly/310.locate\n\n");
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
check_size(char *db)
|
||||
{
|
||||
struct stat sb;
|
||||
off_t len;
|
||||
|
||||
if (stat(db, &sb) == -1) {
|
||||
warnx("the locate database '%s' does not exists.", db);
|
||||
rebuild_message(db);
|
||||
return(0);
|
||||
}
|
||||
len = sb.st_size;
|
||||
|
||||
if (len < (2 * NBG)) {
|
||||
warnx("the locate database '%s' is less than %d bytes large.", db, (2 * NBG));
|
||||
rebuild_message(db);
|
||||
return(0);
|
||||
}
|
||||
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user