1
0
mirror of https://github.com/cookiengineer/audacity synced 2026-02-09 13:12:17 +01:00

Rewrite DirManager::EnsureSafeFileName without downcasts...

... weakening but not yet eliminating dependency on BlockFile subclasses
This commit is contained in:
Paul Licameli
2019-05-14 12:58:20 -04:00
parent d46bb29e3a
commit 81d4c217e6
5 changed files with 50 additions and 27 deletions

View File

@@ -1581,25 +1581,11 @@ bool DirManager::EnsureSafeFilename(const wxFileName &fName)
{
BlockFilePtr b = iter->second.lock();
if (b) {
// don't worry, we don't rely on this cast unless IsAlias is true
auto ab = static_cast< AliasBlockFile * > ( &*b );
// don't worry, we don't rely on this cast unless ISDataAvailable is false
// which means that it still needs to access the file.
auto db = static_cast< ODDecodeBlockFile * > ( &*b );
if (b->IsAlias() && ab->GetAliasedFileName() == fName) {
if (fName.IsOk() && b->GetExternalFileName() == fName) {
needToRename = true;
//ODBlocks access the aliased file on another thread, so we need to pause them before this continues.
readLocks.push_back( ab->LockForRead() );
}
//now for encoded OD blocks (e.g. flac)
else if (!b->IsDataAvailable() && db->GetEncodedAudioFilename() == fName) {
needToRename = true;
//ODBlocks access the aliased file on another thread, so we need to pause them before this continues.
readLocks.push_back( db->LockForRead() );
readLocks.push_back( b->LockForRead() );
}
}
++iter;
@@ -1631,19 +1617,12 @@ bool DirManager::EnsureSafeFilename(const wxFileName &fName)
{
BlockFilePtr b = iter2->second.lock();
if (b) {
auto ab = static_cast< AliasBlockFile * > ( &*b );
auto db = static_cast< ODDecodeBlockFile * > ( &*b );
if (b->IsAlias() && ab->GetAliasedFileName() == fName)
{
ab->ChangeAliasedFileName(wxFileNameWrapper{ renamedFileName });
if (fName.IsOk() && b->GetExternalFileName() == fName) {
b->SetExternalFileName(wxFileNameWrapper{ renamedFileName });
wxPrintf(_("Changed block %s to new alias name\n"),
b->GetFileName().name.GetFullName());
}
else if (!b->IsDataAvailable() && db->GetEncodedAudioFilename() == fName) {
db->ChangeAudioFile(wxFileNameWrapper{ renamedFileName });
}
}
++iter2;
}