#include <chrono>
#include <getopt.h>
#include <iosfwd>
+#include <locale.h>
#include <math.h>
#include <memory>
#include <random>
int type = getc(fp);
if (type == DBE_NORMAL) {
string filename = read_cstr(fp);
- receiver->add_file(dir_path + "/" + filename);
+ receiver->add_file(dir_path + "/" + filename, unknown_dir_time);
} else if (type == DBE_DIRECTORY) {
string dirname = read_cstr(fp);
- receiver->add_file(dir_path + "/" + dirname);
+ receiver->add_file(dir_path + "/" + dirname, unknown_dir_time);
} else {
return; // Probably end.
}
}
if (!s.empty() && s.back() == '\n')
s.pop_back();
- receiver->add_file(move(s));
+ receiver->add_file(move(s), unknown_dir_time);
}
}
}
}
-void do_build(const char *infile, const char *outfile, int block_size, bool plaintext)
+void do_build(const char *infile, const char *outfile, int block_size, bool plaintext, bool check_visibility)
{
FILE *infp = fopen(infile, "rb");
if (infp == nullptr) {
}
string dictionary = builder.train(1024);
- DatabaseBuilder db(outfile, block_size, dictionary);
- Corpus *corpus = db.start_corpus();
+ DatabaseBuilder db(outfile, /*owner=*/-1, block_size, dictionary, check_visibility);
+ DatabaseReceiver *corpus = db.start_corpus(/*store_dir_times=*/false);
if (plaintext) {
read_plaintext(infp, corpus);
} else {
}
fclose(infp);
- dprintf("Read %zu files from %s\n", corpus->num_files, infile);
+ dprintf("Read %zu files from %s\n", corpus->num_files_seen(), infile);
db.finish_corpus();
}
"\n"
" -b, --block-size SIZE number of filenames to store in each block (default 32)\n"
" -p, --plaintext input is a plaintext file, not an mlocate database\n"
+ " -l, --require-visibility FLAG check visibility before reporting files\n"
" --help print this help\n"
" --version print version information\n");
}
void version()
{
- printf("plocate-build %s\n", PLOCATE_VERSION);
+ printf("plocate-build %s\n", PACKAGE_VERSION);
printf("Copyright 2020 Steinar H. Gunderson\n");
printf("License GPLv2+: GNU GPL version 2 or later <https://gnu.org/licenses/gpl.html>.\n");
printf("This is free software: you are free to change and redistribute it.\n");
printf("There is NO WARRANTY, to the extent permitted by law.\n");
}
+bool parse_bool(const string &str, bool *result)
+{
+ if (str == "0" || str == "no") {
+ *result = false;
+ return true;
+ }
+ if (str == "1" || str == "yes") {
+ *result = true;
+ return true;
+ }
+ return false;
+}
+
int main(int argc, char **argv)
{
static const struct option long_options[] = {
{ "block-size", required_argument, 0, 'b' },
{ "plaintext", no_argument, 0, 'p' },
+ { "require-visibility", required_argument, 0, 'l' },
{ "help", no_argument, 0, 'h' },
{ "version", no_argument, 0, 'V' },
{ "debug", no_argument, 0, 'D' }, // Not documented.
int block_size = 32;
bool plaintext = false;
+ bool check_visibility = true;
setlocale(LC_ALL, "");
for (;;) {
int option_index = 0;
- int c = getopt_long(argc, argv, "b:hpVD", long_options, &option_index);
+ int c = getopt_long(argc, argv, "b:hpl:VD", long_options, &option_index);
if (c == -1) {
break;
}
case 'p':
plaintext = true;
break;
+ case 'l':
+ if (!parse_bool(optarg, &check_visibility) != 0) {
+ fprintf(stderr, "plocate-build: invalid value `%s' for --%s\n",
+ optarg, "require-visibility");
+ exit(EXIT_FAILURE);
+ }
+ break;
case 'h':
usage();
exit(0);
exit(1);
}
- do_build(argv[optind], argv[optind + 1], block_size, plaintext);
+ do_build(argv[optind], argv[optind + 1], block_size, plaintext, check_visibility);
exit(EXIT_SUCCESS);
}