From cedcfbe33057ae84cc577e2a9caca00e3e7170fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Rou=C3=A9?= Date: Thu, 1 Jun 2023 17:26:04 +0200 Subject: [PATCH] Mark opportunities for snapshot creation failure (including #1383) --- GRDB/Core/DatabasePool.swift | 3 +++ GRDB/Core/DatabaseSnapshotPool.swift | 1 + 2 files changed, 4 insertions(+) diff --git a/GRDB/Core/DatabasePool.swift b/GRDB/Core/DatabasePool.swift index b89f0c4c1..ed760e651 100644 --- a/GRDB/Core/DatabasePool.swift +++ b/GRDB/Core/DatabasePool.swift @@ -669,6 +669,7 @@ extension DatabasePool: DatabaseReader { #if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER && (compiler(>=5.7.1) || !(os(macOS) || targetEnvironment(macCatalyst)))) /// Returns a long-lived WAL snapshot transaction on a reader connection. func walSnapshotTransaction() throws -> WALSnapshotTransaction { + // TODO #1383: might fail if wal file is truncated guard let readerPool else { throw DatabaseError.connectionIsClosed() } @@ -687,6 +688,7 @@ extension DatabasePool: DatabaseReader { /// - important: The `completion` argument is executed in a serial /// dispatch queue, so make sure you use the transaction asynchronously. func asyncWALSnapshotTransaction(_ completion: @escaping (Result) -> Void) { + // TODO #1383: might fail if wal file is truncated guard let readerPool else { completion(.failure(DatabaseError.connectionIsClosed())) return @@ -904,6 +906,7 @@ extension DatabasePool { /// if this method is called from a database access where a write /// transaction is open. public func makeSnapshotPool() throws -> DatabaseSnapshotPool { + // TODO #1383: might fail if wal file is truncated try unsafeReentrantRead { db in try DatabaseSnapshotPool(db) } diff --git a/GRDB/Core/DatabaseSnapshotPool.swift b/GRDB/Core/DatabaseSnapshotPool.swift index 8701754a4..8560ca7a7 100644 --- a/GRDB/Core/DatabaseSnapshotPool.swift +++ b/GRDB/Core/DatabaseSnapshotPool.swift @@ -186,6 +186,7 @@ public final class DatabaseSnapshotPool { /// - configuration: A configuration. /// - throws: A ``DatabaseError`` whenever an SQLite error occurs. public init(path: String, configuration: Configuration = Configuration()) throws { + // TODO #1383: might fail if wal file is truncated var configuration = Self.configure(configuration) // Acquire and hold WAL snapshot