diff --git a/src/hnsw/build.c b/src/hnsw/build.c index f2480df4c..6b5c554c4 100644 --- a/src/hnsw/build.c +++ b/src/hnsw/build.c @@ -426,9 +426,9 @@ static void BuildIndex( struct stat index_file_stat; char *result_buf = NULL; char *tmp_index_file_path = NULL; - const char *tmp_index_file_fmt_str = "/tmp/ldb-index-%d.bin"; - // size of static name + max digits of uint32 (Oid) 10 + 1 for nullbyte and - 2 for %d format specifier - const uint32 tmp_index_file_char_cnt = strlen(tmp_index_file_fmt_str) + 9; + const char *tmp_index_file_fmt_str = "%s/ldb-index-%d.bin"; + // parent_dir + max digits of uint32 (Oid) 10 + const uint32 tmp_index_file_char_cnt = MAXPGPATH + strlen(tmp_index_file_fmt_str) + 10; int index_file_fd; int munmap_ret; usearch_metadata_t metadata; @@ -514,10 +514,11 @@ static void BuildIndex( if(buildstate->index_file_path == NULL) { // Save index into temporary file // To later mmap it into memory - // Filename is /tmp/ldb-index-$relfilenode.bin // The file will be removed in the end tmp_index_file_path = palloc0(tmp_index_file_char_cnt); - snprintf(tmp_index_file_path, tmp_index_file_char_cnt, tmp_index_file_fmt_str, index->rd_rel->relfilenode); + // Create index file directory string: $pg_data_dir/ldb_indexes/index-$relfilenode.bin + snprintf( + tmp_index_file_path, tmp_index_file_char_cnt, tmp_index_file_fmt_str, DataDir, index->rd_rel->relfilenode); usearch_save(buildstate->usearch_index, tmp_index_file_path, NULL, &error); assert(error == NULL); index_file_fd = open(tmp_index_file_path, O_RDONLY);