Skip to content

Commit f619a5b

Browse files
committed
Fix open logic to match
1 parent 41a5138 commit f619a5b

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

FirebaseRemoteConfig/SwiftNew/DatabaseActor.swift

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,28 +49,32 @@ actor DatabaseActor {
4949
return
5050
}
5151

52-
var flags = SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE | SQLITE_OPEN_FULLMUTEX
53-
#if SQLITE_OPEN_FILEPROTECTION_COMPLETEUNTILFIRSTUSERAUTHENTICATION
54-
flags |= SQLITE_OPEN_FILEPROTECTION_COMPLETEUNTILFIRSTUSERAUTHENTICATION
55-
#endif
52+
let flags = SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE | SQLITE_OPEN_FULLMUTEX |
53+
SQLITE_OPEN_FILEPROTECTION_COMPLETEUNTILFIRSTUSERAUTHENTICATION
5654
if sqlite3_open_v2(cDbPath, &database, flags, nil) == SQLITE_OK {
5755
// Always try to create table if not exists for backward compatibility.
5856
if !createTableSchema() {
5957
// Remove database before failing.
6058
removeDatabase(atPath: dbPath)
59+
// If it failed again, there's nothing we can do here.
6160
RCLog.error("I-RCN000010", "Failed to create table.")
6261
// Create a new database if existing database file is corrupted.
63-
if createFilePath(ifNotExist: dbPath),
64-
sqlite3_open_v2(cDbPath, &database, flags, nil) == SQLITE_OK,
65-
createTableSchema() {
66-
// Exclude the app data used from iCloud backup.
67-
addSkipBackupAttribute(toItemAtPath: dbPath)
62+
if !createFilePath(ifNotExist: dbPath) {
63+
return
64+
}
65+
if sqlite3_open_v2(cDbPath, &database, flags, nil) == SQLITE_OK {
66+
if !createTableSchema() {
67+
// Remove database before fail.
68+
removeDatabase(atPath: dbPath)
69+
// If it failed again, there's nothing we can do here.
70+
RCLog.error("I-RCN000010", "Failed to create table.")
71+
} else {
72+
// Exclude the app data used from iCloud backup.
73+
addSkipBackupAttribute(toItemAtPath: dbPath)
74+
}
6875
} else {
69-
removeDatabase(atPath: dbPath)
70-
// If it failed again, there's nothing we can do here.
71-
RCLog.error("I-RCN000010", "Failed to create table.")
76+
logDatabaseError()
7277
}
73-
7478
} else {
7579
// DB file already exists. Migrate any V1 namespace column entries to V2 fully qualified
7680
// 'namespace:FIRApp' entries.

0 commit comments

Comments
 (0)