mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Add an option to give up
This commit is contained in:
parent
77812fe0b4
commit
92b505c593
@ -298,7 +298,7 @@ public final class SqliteValueBox: ValueBox {
|
|||||||
|
|
||||||
postboxLog("Did open DB at \(path)")
|
postboxLog("Did open DB at \(path)")
|
||||||
|
|
||||||
//sqlite3_busy_timeout(database.handle, 1000 * 10000)
|
sqlite3_busy_timeout(database.handle, 5 * 1000)
|
||||||
|
|
||||||
var resultCode: Bool = true
|
var resultCode: Bool = true
|
||||||
|
|
||||||
@ -421,8 +421,6 @@ public final class SqliteValueBox: ValueBox {
|
|||||||
|
|
||||||
postboxLog("Did set up encryption")
|
postboxLog("Did set up encryption")
|
||||||
|
|
||||||
//sqlite3_busy_timeout(database.handle, 1000 * 10000)
|
|
||||||
|
|
||||||
//database.execute("PRAGMA cache_size=-2097152")
|
//database.execute("PRAGMA cache_size=-2097152")
|
||||||
resultCode = database.execute("PRAGMA mmap_size=0")
|
resultCode = database.execute("PRAGMA mmap_size=0")
|
||||||
assert(resultCode)
|
assert(resultCode)
|
||||||
@ -543,7 +541,19 @@ public final class SqliteValueBox: ValueBox {
|
|||||||
private func isEncrypted(_ database: Database) -> Bool {
|
private func isEncrypted(_ database: Database) -> Bool {
|
||||||
var statement: OpaquePointer? = nil
|
var statement: OpaquePointer? = nil
|
||||||
postboxLog("isEncrypted prepare...")
|
postboxLog("isEncrypted prepare...")
|
||||||
|
|
||||||
|
let allIsOk = Atomic<Bool>(value: false)
|
||||||
|
let databasePath = self.databasePath
|
||||||
|
DispatchQueue.global().asyncAfter(deadline: .now() + 5.0, execute: {
|
||||||
|
if allIsOk.with({ $0 }) == false {
|
||||||
|
postboxLog("Timeout reached, discarding database")
|
||||||
|
try? FileManager.default.removeItem(atPath: databasePath)
|
||||||
|
|
||||||
|
preconditionFailure()
|
||||||
|
}
|
||||||
|
})
|
||||||
let status = sqlite3_prepare_v2(database.handle, "SELECT * FROM sqlite_master LIMIT 1", -1, &statement, nil)
|
let status = sqlite3_prepare_v2(database.handle, "SELECT * FROM sqlite_master LIMIT 1", -1, &statement, nil)
|
||||||
|
let _ = allIsOk.swap(true)
|
||||||
postboxLog("isEncrypted prepare done")
|
postboxLog("isEncrypted prepare done")
|
||||||
if statement == nil {
|
if statement == nil {
|
||||||
postboxLog("isEncrypted: sqlite3_prepare_v2 status = \(status) [\(self.databasePath)]")
|
postboxLog("isEncrypted: sqlite3_prepare_v2 status = \(status) [\(self.databasePath)]")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user