mirror of
http://git.sesse.net/plocate
synced 2025-10-05 23:42:49 +02:00
Fix an issue where the database could be built with the wrong check_visibility flag.
The check_visibility flag would never be set in the header, and thus be set to some random variable instead of what the user wanted.
This commit is contained in:
@@ -11,7 +11,7 @@ using namespace std;
|
||||
|
||||
void AccessRXCache::check_access(const char *filename, bool allow_async, function<void(bool)> cb)
|
||||
{
|
||||
if (!require_visibility) {
|
||||
if (!check_visibility) {
|
||||
cb(true);
|
||||
return;
|
||||
}
|
||||
|
@@ -12,8 +12,8 @@ class IOUringEngine;
|
||||
|
||||
class AccessRXCache {
|
||||
public:
|
||||
AccessRXCache(IOUringEngine *engine, bool require_visibility)
|
||||
: engine(engine), require_visibility(require_visibility) {}
|
||||
AccessRXCache(IOUringEngine *engine, bool check_visibility)
|
||||
: engine(engine), check_visibility(check_visibility) {}
|
||||
void check_access(const char *filename, bool allow_async, std::function<void(bool)> cb);
|
||||
|
||||
private:
|
||||
@@ -25,7 +25,7 @@ private:
|
||||
std::map<std::string, std::vector<PendingStat>> pending_stats;
|
||||
IOUringEngine *engine;
|
||||
std::mutex mu;
|
||||
bool require_visibility;
|
||||
bool check_visibility;
|
||||
};
|
||||
|
||||
#endif // !defined(_ACCESS_RX_CACHE_H)
|
||||
|
@@ -417,7 +417,7 @@ unique_ptr<Trigram[]> create_hashtable(Corpus &corpus, const vector<uint32_t> &a
|
||||
return ht;
|
||||
}
|
||||
|
||||
DatabaseBuilder::DatabaseBuilder(const char *outfile, gid_t owner, int block_size, string dictionary)
|
||||
DatabaseBuilder::DatabaseBuilder(const char *outfile, gid_t owner, int block_size, string dictionary, bool check_visibility)
|
||||
: outfile(outfile), block_size(block_size)
|
||||
{
|
||||
umask(0027);
|
||||
@@ -456,6 +456,7 @@ DatabaseBuilder::DatabaseBuilder(const char *outfile, gid_t owner, int block_siz
|
||||
hdr.max_version = 2;
|
||||
hdr.filename_index_offset_bytes = -1;
|
||||
hdr.zstd_dictionary_length_bytes = -1;
|
||||
hdr.check_visibility = check_visibility;
|
||||
fwrite(&hdr, sizeof(hdr), 1, outfp);
|
||||
|
||||
if (dictionary.empty()) {
|
||||
|
@@ -101,7 +101,7 @@ private:
|
||||
|
||||
class DatabaseBuilder {
|
||||
public:
|
||||
DatabaseBuilder(const char *outfile, gid_t owner, int block_size, std::string dictionary);
|
||||
DatabaseBuilder(const char *outfile, gid_t owner, int block_size, std::string dictionary, bool check_visibility);
|
||||
Corpus *start_corpus(bool store_dir_times);
|
||||
void set_next_dictionary(std::string next_dictionary);
|
||||
void set_conf_block(std::string conf_block);
|
||||
|
2
db.h
2
db.h
@@ -26,7 +26,7 @@ struct Header {
|
||||
uint64_t conf_block_offset_bytes;
|
||||
|
||||
// Only if max_version >= 2.
|
||||
bool require_visibility;
|
||||
bool check_visibility;
|
||||
};
|
||||
|
||||
struct Trigram {
|
||||
|
@@ -166,7 +166,7 @@ void do_build(const char *infile, const char *outfile, int block_size, bool plai
|
||||
}
|
||||
string dictionary = builder.train(1024);
|
||||
|
||||
DatabaseBuilder db(outfile, /*owner=*/-1, block_size, dictionary);
|
||||
DatabaseBuilder db(outfile, /*owner=*/-1, block_size, dictionary, /*check_visibility=*/true);
|
||||
Corpus *corpus = db.start_corpus(/*store_dir_times=*/false);
|
||||
if (plaintext) {
|
||||
read_plaintext(infp, corpus);
|
||||
|
@@ -107,7 +107,7 @@ Corpus::Corpus(int fd, IOUringEngine *engine)
|
||||
}
|
||||
if (hdr.max_version < 2) {
|
||||
// This too. (We ignore the other max_version 2 fields.)
|
||||
hdr.require_visibility = true;
|
||||
hdr.check_visibility = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ void scan_file_block(const vector<Needle> &needles, string_view compressed,
|
||||
size_t scan_docids(const vector<Needle> &needles, const vector<uint32_t> &docids, const Corpus &corpus, IOUringEngine *engine)
|
||||
{
|
||||
Serializer docids_in_order;
|
||||
AccessRXCache access_rx_cache(engine, corpus.get_hdr().require_visibility);
|
||||
AccessRXCache access_rx_cache(engine, corpus.get_hdr().check_visibility);
|
||||
atomic<uint64_t> matched{ 0 };
|
||||
for (size_t i = 0; i < docids.size(); ++i) {
|
||||
uint32_t docid = docids[i];
|
||||
@@ -310,7 +310,7 @@ uint64_t scan_all_docids(const vector<Needle> &needles, int fd, const Corpus &co
|
||||
}
|
||||
}
|
||||
|
||||
AccessRXCache access_rx_cache(nullptr, corpus.get_hdr().require_visibility);
|
||||
AccessRXCache access_rx_cache(nullptr, corpus.get_hdr().check_visibility);
|
||||
Serializer serializer;
|
||||
uint32_t num_blocks = corpus.get_num_filename_blocks();
|
||||
unique_ptr<uint64_t[]> offsets(new uint64_t[num_blocks + 1]);
|
||||
|
@@ -767,7 +767,7 @@ int main(int argc, char **argv)
|
||||
owner = grp->gr_gid;
|
||||
}
|
||||
|
||||
DatabaseBuilder db(conf_output.c_str(), owner, conf_block_size, existing_db.read_next_dictionary());
|
||||
DatabaseBuilder db(conf_output.c_str(), owner, conf_block_size, existing_db.read_next_dictionary(), conf_check_visibility);
|
||||
db.set_conf_block(conf_block);
|
||||
Corpus *corpus = db.start_corpus(/*store_dir_times=*/true);
|
||||
|
||||
|
Reference in New Issue
Block a user