1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-12-31 08:58:43 +01:00

Fail safe save as (#606)

* ProjectFileIO::SaveProject() won't close original db until done...

... So on the failure path, don't risk closing the original too early, failing
with the new database, and then failing to reopen the original.

Just keep the original open and a new connection open too, until it is
certain that the initial population of the new database is successful.

* Check return value from AutoSaveDelete when saving-as

* Fix the remaining unchecked sqlite3_bind* calls, which are in Autosave...

...similarly to checks in 8b3f9fa

* When saving-as or -copy, open the new database only once

* Check return value from sqlite_initialize
This commit is contained in:
Paul Licameli
2020-07-07 16:41:33 -04:00
committed by GitHub
parent ba7ebbb032
commit 590d8c6d09
4 changed files with 149 additions and 52 deletions

View File

@@ -35,6 +35,10 @@ class ProjectFileIO final
, public std::enable_shared_from_this<ProjectFileIO>
{
public:
// Call this static function once before constructing any instances of this
// class. Reinvocations have no effect. Return value is true for success.
static bool InitializeSQL();
static ProjectFileIO &Get( AudacityProject &project );
static const ProjectFileIO &Get( const AudacityProject &project );
@@ -114,6 +118,19 @@ private:
// if opening fails.
sqlite3 *DB();
// Put the current database connection aside, keeping it open, so that
// another may be opened with OpenDB()
void SaveConnection();
// Close any set-aside connection
void DiscardConnection();
// Close any current connection and switch back to using the saved
void RestoreConnection();
// Use a connection that is already open rather than invoke OpenDB
void UseConnection( sqlite3 *db );
sqlite3 *OpenDB(FilePath fileName = {});
bool CloseDB();
bool DeleteDB();
@@ -129,7 +146,8 @@ private:
bool InstallSchema();
bool UpgradeSchema();
bool CopyTo(const FilePath &destpath);
// Return a database connection if successful, which caller must close
sqlite3 *CopyTo(const FilePath &destpath);
void SetError(const TranslatableString & msg);
void SetDBError(const TranslatableString & msg);
@@ -153,6 +171,7 @@ private:
// Bypass transactions if database will be deleted after close
bool mBypass;
sqlite3 *mPrevDB;
sqlite3 *mDB;
FilePath mDBPath;
TranslatableString mLastError;