]> git.sesse.net Git - plocate/blobdiff - plocate.cpp
Return 1 if no matches were found
[plocate] / plocate.cpp
index a1cd97a4a4645c08880b014d4799f9d4c33182f6..7182ee892dfa839b5b50794a4e22582500759996 100644 (file)
@@ -367,7 +367,7 @@ uint64_t scan_all_docids(const vector<Needle> &needles, int fd, const Corpus &co
                                string compressed;
 
                                {
-                                       unique_lock<mutex> lock(mu);
+                                       unique_lock lock(mu);
                                        queue_added.wait(lock, [&work_queue, &done] { return !work_queue.empty() || done; });
                                        if (done && work_queue.empty()) {
                                                return;
@@ -397,7 +397,7 @@ uint64_t scan_all_docids(const vector<Needle> &needles, int fd, const Corpus &co
                complete_pread(fd, &compressed[0], io_len, offsets[io_docid]);
 
                {
-                       unique_lock<mutex> lock(mu);
+                       unique_lock lock(mu);
                        queue_removed.wait(lock, [&work_queue] { return work_queue.size() < 256; });  // Allow ~2MB of data queued up.
                        work_queue.emplace_back(io_docid, last_docid, move(compressed));
                        queue_added.notify_one();  // Avoid the thundering herd.
@@ -571,7 +571,7 @@ uint64_t do_search_file(const vector<Needle> &needles, const std::string &filena
                                                        if (only_count) {
                                                                printf("0\n");
                                                        }
-                                                       exit(0);
+                                                       exit(1);
                                                }
                                        }
                                }
@@ -972,7 +972,7 @@ int main(int argc, char **argv)
        }
        if (needles.empty()) {
                fprintf(stderr, "plocate: no pattern to search for specified\n");
-               exit(0);
+               exit(1);
        }
 
        if (dbpaths.empty()) {
@@ -1000,4 +1000,6 @@ int main(int argc, char **argv)
        if (only_count) {
                printf("%" PRId64 "\n", matched);
        }
+
+       return matched == 0;
 }