mirror of
https://github.com/cookiengineer/audacity
synced 2025-07-04 22:49:07 +02:00
Fix save project (#624)
* Fix typos in comments * Correct the cleanup control flow in ProjectFileIO::SaveProject... ... so that it will not destroy the connection to the original database in case CopyTo() the new file name fails.
This commit is contained in:
parent
b0a89070c2
commit
f7400d86e9
@ -827,6 +827,7 @@ bool ProjectFileIO::InstallSchema(sqlite3 *db, const char *schema /* = "main" */
|
||||
|
||||
bool ProjectFileIO::UpgradeSchema()
|
||||
{
|
||||
// To do
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -855,7 +856,7 @@ bool ProjectFileIO::CheckForOrphans(BlockIDs &blockids)
|
||||
sqlite3_create_function(db, "inset", 1, SQLITE_UTF8 | SQLITE_DETERMINISTIC, nullptr, nullptr, nullptr, nullptr);
|
||||
});
|
||||
|
||||
// Add the function used to verify each rows blockid against the set of active blockids
|
||||
// Add the function used to verify each row's blockid against the set of active blockids
|
||||
rc = sqlite3_create_function(db, "inset", 1, SQLITE_UTF8 | SQLITE_DETERMINISTIC, &blockids, InSet, nullptr, nullptr);
|
||||
if (rc != SQLITE_OK)
|
||||
{
|
||||
@ -1125,7 +1126,7 @@ bool ProjectFileIO::ShouldVacuum(const std::shared_ptr<TrackList> &tracks)
|
||||
const auto &sb = block.sb;
|
||||
auto blockid = sb->GetBlockID();
|
||||
|
||||
// Accumulate space used by the block if the blocckid has not
|
||||
// Accumulate space used by the block if the blockid has not
|
||||
// yet been seen
|
||||
if (active.count(blockid) == 0)
|
||||
{
|
||||
@ -1187,11 +1188,11 @@ void ProjectFileIO::Vacuum(const std::shared_ptr<TrackList> &tracks)
|
||||
// Haven't vacuumed yet
|
||||
mWasVacuumed = false;
|
||||
|
||||
// Assume we do until we found out othersize. That way cleanup at project
|
||||
// Assume we do until we found out otherwise. That way cleanup at project
|
||||
// close time will still occur
|
||||
mHadUnused = true;
|
||||
|
||||
// Don't vacuum if this is a temporary project or if it's deteremined there not
|
||||
// Don't vacuum if this is a temporary project or if it's determined there are not
|
||||
// enough unused blocks to make it worthwhile
|
||||
if (IsTemporary() || !ShouldVacuum(tracks))
|
||||
{
|
||||
@ -2128,9 +2129,32 @@ bool ProjectFileIO::SaveProject(const FilePath &fileName)
|
||||
wxString origName;
|
||||
bool wasTemp = false;
|
||||
bool success = false;
|
||||
sqlite3 *newDB = nullptr;
|
||||
|
||||
// Should probably simplify all of the following by using renames.
|
||||
|
||||
// If we're saving to a different file than the current one, then copy the
|
||||
// current to the new file and make it the active file.
|
||||
if (mFileName != fileName)
|
||||
{
|
||||
// Do NOT prune here since we need to retain the Undo history
|
||||
// after we switch to the new file.
|
||||
newDB = CopyTo(fileName, XO("Saving project"));
|
||||
if (!newDB)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remember the original project filename and temporary status.
|
||||
origName = mFileName;
|
||||
wasTemp = mTemporary;
|
||||
|
||||
// Save the original database connection and try to switch to a new one
|
||||
// (also ensuring closing of one of the connections, with the cooperation
|
||||
// of the finally below)
|
||||
SaveConnection();
|
||||
}
|
||||
|
||||
auto restore = finally([&]
|
||||
{
|
||||
if (!origName.empty())
|
||||
@ -2159,29 +2183,8 @@ bool ProjectFileIO::SaveProject(const FilePath &fileName)
|
||||
}
|
||||
});
|
||||
|
||||
// If we're saving to a different file than the current one, then copy the
|
||||
// current to the new file and make it the active file.
|
||||
if (mFileName != fileName)
|
||||
if (!origName.empty())
|
||||
{
|
||||
// Do NOT prune here since we need to retain the Undo history
|
||||
// after we switch to the new file.
|
||||
auto newDB = CopyTo(fileName, XO("Saving project"));
|
||||
if (!newDB)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remember the original project filename and temporary status. Only do
|
||||
// this after a successful copy so the "finally" block above doesn't monkey
|
||||
// with the files.
|
||||
origName = mFileName;
|
||||
wasTemp = mTemporary;
|
||||
|
||||
// Save the original database connection and try to switch to a new one
|
||||
// (also ensuring closing of one of the connections, with the cooperation
|
||||
// of the finally above)
|
||||
SaveConnection();
|
||||
|
||||
// Make the new connection "safe"
|
||||
Config(newDB, SafeConfig);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user