Skip to content

Commit 231b62b

Browse files
authored
Truncate existing temp file in meta_partition constructor (#93)
Ensure the temp file is truncated if it exists.
1 parent 65fe3a0 commit 231b62b

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

include/builders/external_memory_builder_partitioned_phf.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,11 @@ struct external_memory_builder_partitioned_phf {
281281

282282
struct meta_partition {
283283
meta_partition(std::string const& dir_name, uint64_t id)
284-
: m_filename(dir_name + "/pthash.temp." + std::to_string(id)), m_size(0) {}
284+
: m_filename(dir_name + "/pthash.temp." + std::to_string(id)), m_size(0) {
285+
// Truncate the file if it exists from a previous run
286+
std::ofstream truncate(m_filename.c_str(), std::ofstream::binary | std::ofstream::trunc);
287+
truncate.close();
288+
}
285289

286290
void push_back(hash_type hash) {
287291
m_hashes.push_back(hash);
@@ -322,4 +326,4 @@ struct external_memory_builder_partitioned_phf {
322326
};
323327
};
324328

325-
} // namespace pthash
329+
} // namespace pthash

0 commit comments

Comments
 (0)