Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add check for .enc extension to support encryption #467

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ typedef int FileHandle;
#define PBSTR "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"
#define PBWIDTH 60

inline bool file_exists(const std::string &name, bool dirCheck = false)
inline bool file_exists_impl(const std::string &name, bool dirCheck = false)
{
int val;
#ifndef _WINDOWS
Expand Down Expand Up @@ -94,6 +94,29 @@ inline bool file_exists(const std::string &name, bool dirCheck = false)
}
}

inline bool file_exists(const std::string &name, bool dirCheck = false)
{
#ifdef EXEC_ENV_OLS
bool exists = file_exists_impl(name, dirCheck);
if (exists)
{
return true;
}
if (!dirCheck)
{
// try with .enc extension
std::string enc_name = name + ENCRYPTED_EXTENSION;
return file_exists_impl(enc_name, dirCheck);
}
else
{
return exists;
}
#else
return file_exists_impl(name, dirCheck);
#endif
}

inline void open_file_to_write(std::ofstream &writer, const std::string &filename)
{
writer.exceptions(std::ofstream::failbit | std::ofstream::badbit);
Expand Down
6 changes: 4 additions & 2 deletions src/pq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,13 @@ void FixedChunkPQTable::load_pq_centroid_bin(const char *pq_table_file, size_t n
diskann::cout << "Loaded PQ Pivots: #ctrs: " << NUM_PQ_CENTROIDS << ", #dims: " << this->ndims
<< ", #chunks: " << this->n_chunks << std::endl;

if (file_exists(rotmat_file))
{
#ifdef EXEC_ENV_OLS
if (files.fileExists(rotmat_file))
{
diskann::load_bin<float>(files, rotmat_file, (float *&)rotmat_tr, nr, nc);
#else
if (file_exists(rotmat_file))
{
diskann::load_bin<float>(rotmat_file, rotmat_tr, nr, nc);
#endif
if (nr != this->ndims || nc != this->ndims)
Expand Down
Loading