diff options
author | vng <viktor.govako@gmail.com> | 2011-12-14 20:35:27 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:30:14 +0300 |
commit | 0337dd8cb49cd3a62ceb143b04447d8929e44bdc (patch) | |
tree | 113ddec32755dcd3cb1cfdab255d2234a5b98724 /indexer/search_index_builder.cpp | |
parent | e45aca3e8d84ccd2ea63f1f24f8acf024380d928 (diff) |
[search] Use unique temporary file names for index generation.
Diffstat (limited to 'indexer/search_index_builder.cpp')
-rw-r--r-- | indexer/search_index_builder.cpp | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/indexer/search_index_builder.cpp b/indexer/search_index_builder.cpp index fc6a10490b..15887dc8fa 100644 --- a/indexer/search_index_builder.cpp +++ b/indexer/search_index_builder.cpp @@ -93,31 +93,37 @@ struct MaxValueCalc } // unnamed namespace -void indexer::BuildSearchIndex(FeaturesVector const & featuresVector, Writer & writer) +void indexer::BuildSearchIndex(FeaturesVector const & featuresVector, Writer & writer, + string const & tmpFilePath) { - StringsFile names; - string const tmpFile = GetPlatform().WritablePathForFile("search_index_1.tmp"); - { - FileWriter writer(tmpFile); - names.OpenForWrite(&writer); - featuresVector.ForEachOffset(FeatureInserter(names)); - } + StringsFile names; + + { + FileWriter writer(tmpFilePath); + names.OpenForWrite(&writer); + featuresVector.ForEachOffset(FeatureInserter(names)); + } - names.OpenForRead(new FileReader(tmpFile)); - names.SortStrings(); + names.OpenForRead(new FileReader(tmpFilePath)); + names.SortStrings(); - trie::Build(writer, names.Begin(), names.End(), - trie::builder::MaxValueEdgeBuilder<MaxValueCalc>()); + trie::Build(writer, names.Begin(), names.End(), + trie::builder::MaxValueEdgeBuilder<MaxValueCalc>()); - FileWriter::DeleteFileX(tmpFile); + // at this point all readers should be dead + } + + FileWriter::DeleteFileX(tmpFilePath); } -bool indexer::BuildSearchIndexFromDatFile(string const & datFile) +bool indexer::BuildSearchIndexFromDatFile(string const & fName) { try { - string const tmpFile = GetPlatform().WritablePathForFile("search_index_2.tmp"); + Platform & pl = GetPlatform(); + string const datFile = pl.WritablePathForFile(fName); + string const tmpFile = pl.WritablePathForFile(fName + ".search_index_2.tmp"); { FilesContainerR readCont(datFile); @@ -128,13 +134,15 @@ bool indexer::BuildSearchIndexFromDatFile(string const & datFile) FeaturesVector featuresVector(readCont, header); FileWriter writer(tmpFile); - BuildSearchIndex(featuresVector, writer); + BuildSearchIndex(featuresVector, writer, pl.WritablePathForFile(fName + ".search_index_1.tmp")); } - // Write to container in reversed order. - FilesContainerW writeCont(datFile, FileWriter::OP_WRITE_EXISTING); - FileWriter writer = writeCont.GetWriter(SEARCH_INDEX_FILE_TAG); - rw_ops::Reverse(FileReader(tmpFile), writer); + { + // Write to container in reversed order. + FilesContainerW writeCont(datFile, FileWriter::OP_WRITE_EXISTING); + FileWriter writer = writeCont.GetWriter(SEARCH_INDEX_FILE_TAG); + rw_ops::Reverse(FileReader(tmpFile), writer); + } FileWriter::DeleteFileX(tmpFile); } |