Skip to content

Commit

Permalink
Fix open logic to match
Browse files Browse the repository at this point in the history
  • Loading branch information
paulb777 committed Nov 22, 2024
1 parent 41a5138 commit f619a5b
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions FirebaseRemoteConfig/SwiftNew/DatabaseActor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,32 @@ actor DatabaseActor {
return
}

var flags = SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE | SQLITE_OPEN_FULLMUTEX
#if SQLITE_OPEN_FILEPROTECTION_COMPLETEUNTILFIRSTUSERAUTHENTICATION
flags |= SQLITE_OPEN_FILEPROTECTION_COMPLETEUNTILFIRSTUSERAUTHENTICATION
#endif
let flags = SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE | SQLITE_OPEN_FULLMUTEX |
SQLITE_OPEN_FILEPROTECTION_COMPLETEUNTILFIRSTUSERAUTHENTICATION
if sqlite3_open_v2(cDbPath, &database, flags, nil) == SQLITE_OK {
// Always try to create table if not exists for backward compatibility.
if !createTableSchema() {
// Remove database before failing.
removeDatabase(atPath: dbPath)
// If it failed again, there's nothing we can do here.
RCLog.error("I-RCN000010", "Failed to create table.")
// Create a new database if existing database file is corrupted.
if createFilePath(ifNotExist: dbPath),
sqlite3_open_v2(cDbPath, &database, flags, nil) == SQLITE_OK,
createTableSchema() {
// Exclude the app data used from iCloud backup.
addSkipBackupAttribute(toItemAtPath: dbPath)
if !createFilePath(ifNotExist: dbPath) {
return
}
if sqlite3_open_v2(cDbPath, &database, flags, nil) == SQLITE_OK {
if !createTableSchema() {
// Remove database before fail.
removeDatabase(atPath: dbPath)
// If it failed again, there's nothing we can do here.
RCLog.error("I-RCN000010", "Failed to create table.")
} else {
// Exclude the app data used from iCloud backup.
addSkipBackupAttribute(toItemAtPath: dbPath)
}
} else {
removeDatabase(atPath: dbPath)
// If it failed again, there's nothing we can do here.
RCLog.error("I-RCN000010", "Failed to create table.")
logDatabaseError()
}

} else {
// DB file already exists. Migrate any V1 namespace column entries to V2 fully qualified
// 'namespace:FIRApp' entries.
Expand Down

0 comments on commit f619a5b

Please sign in to comment.