From acc97b197bd7ae2568d742590d09c8d35d56179c Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Tue, 23 Jan 2018 13:33:39 -0500 Subject: [PATCH] Properly force checkpoint at end of conversion // FREEBIE --- Signal/test/util/OWSDatabaseConverterTest.m | 2 ++ SignalMessaging/utils/OWSDatabaseConverter.m | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Signal/test/util/OWSDatabaseConverterTest.m b/Signal/test/util/OWSDatabaseConverterTest.m index 1d671191c..438bfaf8f 100644 --- a/Signal/test/util/OWSDatabaseConverterTest.m +++ b/Signal/test/util/OWSDatabaseConverterTest.m @@ -206,6 +206,8 @@ NS_ASSUME_NONNULL_BEGIN return databaseFilePath; } +#pragma mark - Tests + - (void)testDoesDatabaseNeedToBeConverted_Unconverted { NSData *databasePassword = [self randomDatabasePassword]; diff --git a/SignalMessaging/utils/OWSDatabaseConverter.m b/SignalMessaging/utils/OWSDatabaseConverter.m index 7c75242e6..041e5b65b 100644 --- a/SignalMessaging/utils/OWSDatabaseConverter.m +++ b/SignalMessaging/utils/OWSDatabaseConverter.m @@ -302,8 +302,13 @@ const NSUInteger kSQLCipherSaltLength = 16; } // Force a checkpoint so that the plaintext is written to the actual DB file, not just living in the WAL. - // TODO do we need/want the earlier checkpoint if we're checkpointing here? - sqlite3_wal_autocheckpoint(db, 0); + int log, ckpt; + status = sqlite3_wal_checkpoint_v2(db, NULL, SQLITE_CHECKPOINT_FULL, &log, &ckpt); + if (status != SQLITE_OK) { + DDLogError(@"%@ Error forcing checkpoint. status: %d, log: %d, ckpt: %d, error: %s", self.logTag, status, log, ckpt, sqlite3_errmsg(db)); + return OWSErrorWithCodeDescription( + OWSErrorCodeDatabaseConversionFatalError, @"Error forcing checkpoint."); + } sqlite3_close(db); }