1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-27 06:07:59 +02:00

AUP3: Change journal format to WAL

And remove the deletion of the journal file.
This commit is contained in:
Leland Lucius 2020-07-03 11:34:53 -05:00
parent 48287e9b0d
commit 337e223754
2 changed files with 72 additions and 19 deletions

View File

@ -46,7 +46,8 @@ static const char *ProjectFileSchema =
"PRAGMA application_id = %d;" "PRAGMA application_id = %d;"
"PRAGMA user_version = %d;" "PRAGMA user_version = %d;"
"PRAGMA page_size = %d;" "PRAGMA page_size = %d;"
"PRAGMA journal_mode = DELETE;" "PRAGMA journal_mode = WAL;"
"PRAGMA locking_mode = EXCLUSIVE;"
"" ""
// CREATE SQL project // CREATE SQL project
// doc is a variable sized XML text string. // doc is a variable sized XML text string.
@ -220,9 +221,6 @@ ProjectFileIO::~ProjectFileIO()
// the recovery dialog upon next restart. // the recovery dialog upon next restart.
if (CloseDB()) if (CloseDB())
{ {
// Always remove the journal now that the DB is closed
wxRemoveFile(filename + wxT("-journal"));
// At this point, we are shutting down cleanly and if the project file is // At this point, we are shutting down cleanly and if the project file is
// still in the temp directory it means that the user has chosen not to // still in the temp directory it means that the user has chosen not to
// save it. So, delete it. // save it. So, delete it.
@ -297,10 +295,6 @@ bool ProjectFileIO::CloseDB()
{ {
SetDBError(XO("Failed to close the project file")); SetDBError(XO("Failed to close the project file"));
} }
else
{
wxRemoveFile(mFileName + wxT("-journal"));
}
mDB = nullptr; mDB = nullptr;
SetFileName({}); SetFileName({});
@ -324,8 +318,6 @@ bool ProjectFileIO::DeleteDB()
return false; return false;
} }
wxRemoveFile(mFileName + wxT("-journal"));
} }
} }
@ -345,9 +337,6 @@ bool ProjectFileIO::CleanDB()
{ {
if (CloseDB()) if (CloseDB())
{ {
// This can be removed even if we fail below since the DB is closed
wxRemoveFile(mFileName + wxT("-journal"));
wxString tmppath = wxFileName::CreateTempFileName(mFileName + ".xxxxx"); wxString tmppath = wxFileName::CreateTempFileName(mFileName + ".xxxxx");
if (wxRename(mFileName, tmppath) == 0) if (wxRename(mFileName, tmppath) == 0)
{ {
@ -379,6 +368,69 @@ bool ProjectFileIO::CleanDB()
return false; return false;
} }
bool ProjectFileIO::TransactionStart(const wxString &name)
{
char* errmsg = nullptr;
int rc = sqlite3_exec(DB(),
wxT("SAVEPOINT ") + name + wxT(";"),
nullptr,
nullptr,
&errmsg);
if (errmsg)
{
SetDBError(
XO("Failed to create savepoint:\n\n%s").Format(name)
);
sqlite3_free(errmsg);
}
return rc == SQLITE_OK;
}
bool ProjectFileIO::TransactionCommit(const wxString &name)
{
char* errmsg = nullptr;
int rc = sqlite3_exec(DB(),
wxT("SAVEPOINT ") + name + wxT(";"),
nullptr,
nullptr,
&errmsg);
if (errmsg)
{
SetDBError(
XO("Failed to release savepoint:\n\n%s").Format(name)
);
sqlite3_free(errmsg);
}
return rc == SQLITE_OK;
}
bool ProjectFileIO::TransactionRollback(const wxString &name)
{
char* errmsg = nullptr;
int rc = sqlite3_exec(DB(),
wxT("RELEASE ") + name + wxT(";"),
nullptr,
nullptr,
&errmsg);
if (errmsg)
{
SetDBError(
XO("Failed to release savepoint:\n\n%s").Format(name)
);
sqlite3_free(errmsg);
}
return rc == SQLITE_OK;
}
/* static */ /* static */
int ProjectFileIO::ExecCallback(void *data, int cols, char **vals, char **names) int ProjectFileIO::ExecCallback(void *data, int cols, char **vals, char **names)
{ {
@ -627,9 +679,6 @@ bool ProjectFileIO::CopyTo(const FilePath &destpath)
success = false; success = false;
} }
// Always delete the journal
wxRemoveFile(destpath + wxT("-journal"));
if (!success) if (!success)
{ {
wxRemoveFile(destpath); wxRemoveFile(destpath);
@ -1101,9 +1150,9 @@ bool ProjectFileIO::SaveProject(const FilePath &fileName)
bool wasTemp = false; bool wasTemp = false;
bool success = false; bool success = false;
// Should probably simply all of the by using renames. But, one benefit // Should probably simplify all of the following by using renames. But, one
// of using CopyTo() for new file saves, is that it will be VACUUMED at // benefit of using CopyTo() for new file saves, is that it will be VACUUMED
// the same time. // at the same time.
auto restore = finally([&] auto restore = finally([&]
{ {

View File

@ -114,6 +114,10 @@ private:
bool DeleteDB(); bool DeleteDB();
bool CleanDB(); bool CleanDB();
bool TransactionStart(const wxString &name);
bool TransactionCommit(const wxString &name);
bool TransactionRollback(const wxString &name);
wxString GetValue(const char *sql); wxString GetValue(const char *sql);
bool GetBlob(const char *sql, wxMemoryBuffer &buffer); bool GetBlob(const char *sql, wxMemoryBuffer &buffer);