X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=plocate.cpp;h=a1cd97a4a4645c08880b014d4799f9d4c33182f6;hb=fd6198891d6fd9642effc0843fef6f23b991af3e;hp=1c0b3d0463f09ea04a5f9a39156d91a1e089c7fe;hpb=67c741868bac4d4b845426d8b7e6126f4ec41232;p=plocate diff --git a/plocate.cpp b/plocate.cpp index 1c0b3d0..a1cd97a 100644 --- a/plocate.cpp +++ b/plocate.cpp @@ -66,7 +66,7 @@ ZSTD_DDict *ddict = nullptr; class Corpus { public: - Corpus(int fd, IOUringEngine *engine); + Corpus(int fd, const char *filename_for_errors, IOUringEngine *engine); ~Corpus(); void find_trigram(uint32_t trgm, function cb); void get_compressed_filename_block(uint32_t docid, function cb) const; @@ -84,7 +84,7 @@ public: Header hdr; }; -Corpus::Corpus(int fd, IOUringEngine *engine) +Corpus::Corpus(int fd, const char *filename_for_errors, IOUringEngine *engine) : fd(fd), engine(engine) { if (flush_cache) { @@ -98,11 +98,11 @@ Corpus::Corpus(int fd, IOUringEngine *engine) complete_pread(fd, &hdr, sizeof(hdr), /*offset=*/0); if (memcmp(hdr.magic, "\0plocate", 8) != 0) { - fprintf(stderr, "plocate.db is corrupt or an old version; please rebuild it.\n"); + fprintf(stderr, "%s: database is corrupt or not a plocate database; please rebuild it.\n", filename_for_errors); exit(1); } if (hdr.version != 0 && hdr.version != 1) { - fprintf(stderr, "plocate.db has version %u, expected 0 or 1; please rebuild it.\n", hdr.version); + fprintf(stderr, "%s: has version %u, expected 0 or 1; please rebuild it.\n", filename_for_errors, hdr.version); exit(1); } if (hdr.version == 0) { @@ -489,7 +489,7 @@ uint64_t do_search_file(const vector &needles, const std::string &filena } IOUringEngine engine(/*slop_bytes=*/16); // 16 slop bytes as described in turbopfor.h. - Corpus corpus(fd, &engine); + Corpus corpus(fd, filename.c_str(), &engine); dprintf("Corpus init done after %.1f ms.\n", 1e3 * duration(steady_clock::now() - start).count()); vector trigram_groups; @@ -837,6 +837,7 @@ int main(int argc, char **argv) static const struct option long_options[] = { { "help", no_argument, 0, 'h' }, { "count", no_argument, 0, 'c' }, + { "all", no_argument, 0, 'A' }, { "basename", no_argument, 0, 'b' }, { "database", required_argument, 0, 'd' }, { "existing", no_argument, 0, 'e' }, @@ -857,11 +858,14 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); for (;;) { int option_index = 0; - int c = getopt_long(argc, argv, "bcd:ehil:n:N0rwVD", long_options, &option_index); + int c = getopt_long(argc, argv, "Abcd:ehil:n:N0rwVD", long_options, &option_index); if (c == -1) { break; } switch (c) { + case 'A': + // Ignored. + break; case 'b': match_basename = true; break;