]> git.sesse.net Git - plocate/commitdiff
Move the cache-flushing behavior into an undocumented option, so that one does not...
authorSteinar H. Gunderson <steinar+git@gunderson.no>
Thu, 15 Oct 2020 22:48:23 +0000 (00:48 +0200)
committerSteinar H. Gunderson <steinar+git@gunderson.no>
Thu, 15 Oct 2020 22:48:23 +0000 (00:48 +0200)
options.h
plocate.cpp

index 683c8d3df00a95b72890b6053b316f503809bdfb..68f712e843e487688667531fe183e1b2ca6742ac 100644 (file)
--- a/options.h
+++ b/options.h
@@ -8,6 +8,7 @@ extern bool ignore_case;
 extern bool only_count;
 extern bool print_nul;
 extern bool use_debug;
+extern bool flush_cache;
 extern bool patterns_are_regex;
 extern bool use_extended_regex;
 extern int64_t limit_matches;
index 4141a316bb91a5381bfd01a28163f58341e26fd9..e08c019b84d58f7b74054533010cfb61adfe4c16 100644 (file)
@@ -49,6 +49,7 @@ bool ignore_case = false;
 bool only_count = false;
 bool print_nul = false;
 bool use_debug = false;
+bool flush_cache = false;
 bool patterns_are_regex = false;
 bool use_extended_regex = false;
 int64_t limit_matches = numeric_limits<int64_t>::max();
@@ -80,8 +81,7 @@ public:
 Corpus::Corpus(int fd, IOUringEngine *engine)
        : fd(fd), engine(engine)
 {
-       // Enable to test cold-cache behavior (except for access()).
-       if (false) {
+       if (flush_cache) {
                off_t len = lseek(fd, 0, SEEK_END);
                if (len == -1) {
                        perror("lseek");
@@ -663,6 +663,7 @@ void version()
 int main(int argc, char **argv)
 {
        constexpr int EXTENDED_REGEX = 1000;
+       constexpr int FLUSH_CACHE = 1001;
        static const struct option long_options[] = {
                { "help", no_argument, 0, 'h' },
                { "count", no_argument, 0, 'c' },
@@ -674,6 +675,8 @@ int main(int argc, char **argv)
                { "regexp", no_argument, 0, 'r' },
                { "regex", no_argument, 0, EXTENDED_REGEX },
                { "debug", no_argument, 0, 'D' },  // Not documented.
+               // Enable to test cold-cache behavior (except for access()). Not documented.
+               { "flush-cache", no_argument, 0, FLUSH_CACHE },
                { 0, 0, 0, 0 }
        };
 
@@ -718,6 +721,9 @@ int main(int argc, char **argv)
                case 'D':
                        use_debug = true;
                        break;
+               case FLUSH_CACHE:
+                       flush_cache = true;
+                       break;
                case 'V':
                        version();
                        break;
@@ -726,10 +732,12 @@ int main(int argc, char **argv)
                }
        }
 
-       if (use_debug) {
+       if (use_debug || flush_cache) {
                // Debug information would leak information about which files exist,
                // so drop setgid before we open the file; one would either need to run
-               // as root, or use a locally-built file.
+               // as root, or use a locally-built file. Doing the same thing for
+               // flush_cache is mostly paranoia, in an attempt to prevent random users
+               // from making plocate slow for everyone else.
                if (setgid(getgid()) != 0) {
                        perror("setgid");
                        exit(EXIT_FAILURE);