diff --git a/daemon/postprocess/ParRenamer.cpp b/daemon/postprocess/ParRenamer.cpp index 1949104cd..a38f83d7b 100644 --- a/daemon/postprocess/ParRenamer.cpp +++ b/daemon/postprocess/ParRenamer.cpp @@ -135,8 +135,20 @@ void ParRenamer::LoadParFile(const char* parFilename) continue; } std::string filename = Par2::DiskFile::TranslateFilename(sourceFile->GetDescriptionPacket()->FileName()); - m_fileHashList.emplace_back(filename.c_str(), sourceFile->GetDescriptionPacket()->Hash16k().print().c_str()); - RegisterParredFile(filename.c_str()); + std::string hash = sourceFile->GetDescriptionPacket()->Hash16k().print(); + + bool exists = std::find_if(m_fileHashList.begin(), m_fileHashList.end(), + [&hash](FileHash& fileHash) + { + return !strcmp(fileHash.GetHash(), hash.c_str()); + }) + != m_fileHashList.end(); + + if (!exists) + { + m_fileHashList.emplace_back(filename.c_str(), hash.c_str()); + RegisterParredFile(filename.c_str()); + } } } diff --git a/tests/postprocess/ParRenamerTest.cpp b/tests/postprocess/ParRenamerTest.cpp index f2d57e349..9f5946208 100644 --- a/tests/postprocess/ParRenamerTest.cpp +++ b/tests/postprocess/ParRenamerTest.cpp @@ -88,3 +88,19 @@ TEST_CASE("Par-renamer: detecting missing", "[Par][ParRenamer][Slow][TestData]") REQUIRE(parRenamer.GetRenamedCount() == 1); REQUIRE(parRenamer.HasMissedFiles()); } + +TEST_CASE("Par-renamer: rename dupe par", "[Par][ParRenamer][Slow][TestData]") +{ + Options::CmdOptList cmdOpts; + cmdOpts.push_back("ParRename=yes"); + Options options(&cmdOpts, nullptr); + + ParRenamerMock parRenamer; + FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile.dat").c_str(), (TestUtil::WorkingDir() + "/123456").c_str()); + FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile.vol00+1.par2").c_str(), (TestUtil::WorkingDir() + "/testfile2.par2").c_str()); + parRenamer.SetDetectMissing(true); + parRenamer.Execute(); + + REQUIRE(parRenamer.GetRenamedCount() == 1); + REQUIRE_FALSE(parRenamer.HasMissedFiles()); +}