Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Commit

Permalink
#313: better handling of obfuscated par-files in par-renamer
Browse files Browse the repository at this point in the history
Avoid false detection of missing files.
  • Loading branch information
hugbug committed Dec 4, 2016
1 parent 84f4cf2 commit 13db817
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
16 changes: 14 additions & 2 deletions daemon/postprocess/ParRenamer.cpp
Expand Up @@ -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());
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions tests/postprocess/ParRenamerTest.cpp
Expand Up @@ -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());
}

0 comments on commit 13db817

Please sign in to comment.