1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-04-30 15:49:41 +02:00

Bug2599: -wal and -shm of discarded temp projects should clean up

This commit is contained in:
Paul Licameli 2020-11-24 14:09:26 -05:00
parent 0d5b9753bc
commit 7e1e339f72
3 changed files with 25 additions and 32 deletions

View File

@ -287,25 +287,7 @@ void AutoRecoveryDialog::OnDiscardSelected(wxCommandEvent &WXUNUSED(evt))
wxFileName temp(FileNames::TempDir(), wxT(""));
if (file == temp)
{
if (wxRemoveFile(fileName))
{
if (wxFileExists(fileName + wxT("-shm")))
{
wxRemoveFile(fileName + wxT("-shm"));
}
if (wxFileExists(fileName + wxT("-wal")))
{
wxRemoveFile(fileName + wxT("-wal"));
}
if (wxFileExists(fileName + wxT("-journal")))
{
wxRemoveFile(fileName + wxT("-journal"));
}
}
}
ProjectFileIO::RemoveProject(fileName);
}
else
// Don't remove from disk, but do (later) open the database

View File

@ -392,9 +392,7 @@ void ProjectFileIO::DiscardConnection()
wxFileName file(mPrevFileName);
file.SetFullName(wxT(""));
if (file == temp)
{
wxRemoveFile(mPrevFileName);
}
RemoveProject(mPrevFileName);
}
mPrevConn = nullptr;
mPrevFileName.clear();
@ -742,6 +740,7 @@ bool ProjectFileIO::CopyTo(const FilePath &destpath,
sqlite3_exec(db, "DETACH DATABASE outbound;", nullptr, nullptr, nullptr);
// RemoveProject not necessary to clean up attached database
wxRemoveFile(destpath);
}
});
@ -1051,6 +1050,21 @@ bool ProjectFileIO::MoveProject(const FilePath &src, const FilePath &dst)
return (success = true);
}
bool ProjectFileIO::RemoveProject(const FilePath &filename)
{
if (!wxFileExists(filename))
return false;
bool success = wxRemoveFile(filename);
auto &suffixes = AuxiliaryFileSuffixes();
for (const auto &suffix : suffixes) {
auto file = filename + suffix;
if (wxFileExists(file))
success = wxRemoveFile(file) && success;
}
return success;
}
ProjectFileIO::BackupProject::BackupProject(
ProjectFileIO &projectFileIO, const FilePath &path )
{
@ -1066,13 +1080,7 @@ void ProjectFileIO::BackupProject::Discard()
{
if (!mPath.empty()) {
// Succeeded; don't need the safety files
auto suffixes = AuxiliaryFileSuffixes();
suffixes.push_back({});
for (const auto &suffix : suffixes) {
auto path = mSafety + suffix;
if (wxFileExists(path))
wxRemoveFile(path);
}
RemoveProject(mSafety);
mSafety.clear();
}
}
@ -1171,6 +1179,8 @@ void ProjectFileIO::Compact(
OpenConnection(origName);
}
// Did not achieve any real compaction
// RemoveProject not needed for what was an attached database
wxRemoveFile(tempName);
}
@ -2174,9 +2184,7 @@ bool ProjectFileIO::CloseProject()
wxFileName file(filename);
file.SetFullName(wxT(""));
if (file == temp)
{
wxRemoveFile(filename);
}
RemoveProject(filename);
}
}

View File

@ -137,6 +137,9 @@ private:
bool MoveProject(const FilePath &src, const FilePath &dst);
public:
//! Remove any files associated with a project at given path; return true if successful
static bool RemoveProject(const FilePath &filename);
// Object manages the temporary backing-up of project paths while
// trying to overwrite with new contents, and restoration in case of failure
class BackupProject {