Skip to content

Commit 82945e0

Browse files
committed
Avoid extra metadatabase directory setup
1 parent 9acb0bd commit 82945e0

2 files changed

Lines changed: 10 additions & 39 deletions

File tree

Sources/SQLiteData/CloudKit/Internal/Metadatabase.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@
1313
open "\(url.path(percentEncoded: false))"
1414
"""
1515
)
16-
if !url.isInMemory {
17-
try FileManager.default.createDirectory(
18-
at: url.deletingLastPathComponent(),
19-
withIntermediateDirectories: true
20-
)
21-
}
22-
2316
@Dependency(\.context) var context
2417
guard !url.isInMemory || context != .live
2518
else {

Sources/SQLiteData/CloudKit/SyncEngine.swift

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@
7575
/// you do not want to be shareable with other users.
7676
/// - containerIdentifier: The container identifier in CloudKit to synchronize to. If omitted
7777
/// the container will be determined from the entitlements of your app.
78-
/// - metadatabaseURL: The location of the metadata database used to track CloudKit sync
79-
/// state. If omitted, a default location is derived from the main database path.
8078
/// - defaultZone: The zone for all records to be stored in.
8179
/// - startImmediately: Determines if the sync engine starts right away or requires an
8280
/// explicit call to ``start()``. By default this argument is `true`.
@@ -92,7 +90,6 @@
9290
tables: repeat (each T1).Type,
9391
privateTables: repeat (each T2).Type,
9492
containerIdentifier: String? = nil,
95-
metadatabaseURL: URL? = nil,
9693
defaultZone: CKRecordZone = CKRecordZone(zoneName: "co.pointfree.SQLiteData.defaultZone"),
9794
startImmediately: Bool? = nil,
9895
delegate: (any SyncEngineDelegate)? = nil,
@@ -149,7 +146,6 @@
149146
)
150147
},
151148
userDatabase: userDatabase,
152-
metadatabaseURL: metadatabaseURL,
153149
logger: logger,
154150
delegate: delegate,
155151
tables: allTables,
@@ -199,7 +195,6 @@
199195
)
200196
},
201197
userDatabase: userDatabase,
202-
metadatabaseURL: metadatabaseURL,
203198
logger: logger,
204199
delegate: delegate,
205200
tables: allTables,
@@ -220,7 +215,6 @@
220215
SyncEngine
221216
) -> (private: any SyncEngineProtocol, shared: any SyncEngineProtocol),
222217
userDatabase: UserDatabase,
223-
metadatabaseURL: URL? = nil,
224218
logger: Logger,
225219
delegate: (any SyncEngineDelegate)?,
226220
tables: [any SynchronizableTable],
@@ -264,15 +258,12 @@
264258
self.defaultSyncEngines = defaultSyncEngines
265259
self.userDatabase = userDatabase
266260
self.logger = logger
267-
let resolvedMetadatabaseURL =
268-
try metadatabaseURL
269-
?? URL.metadatabase(
261+
self.metadatabase = try defaultMetadatabase(
262+
logger: logger,
263+
url: try URL.metadatabase(
270264
databasePath: userDatabase.path,
271265
containerIdentifier: container.containerIdentifier
272266
)
273-
self.metadatabase = try defaultMetadatabase(
274-
logger: logger,
275-
url: resolvedMetadatabaseURL
276267
)
277268
self.tablesByName = Dictionary(
278269
uniqueKeysWithValues: self.tables.map { ($0.base.tableName, $0) }
@@ -2220,15 +2211,9 @@
22202211
///
22212212
/// See <doc:PreparingDatabase> for more information on preparing your database.
22222213
///
2223-
/// - Parameters:
2224-
/// - containerIdentifier: The identifier of the CloudKit container used to
2225-
/// synchronize data. Defaults to the value set in the app's entitlements.
2226-
/// - metadatabaseURL: The location of the attached metadata database. If omitted, a default
2227-
/// location is derived from the main database path.
2228-
public func attachMetadatabase(
2229-
containerIdentifier: String? = nil,
2230-
metadatabaseURL: URL? = nil
2231-
) throws {
2214+
/// - Parameter containerIdentifier: The identifier of the CloudKit container used to
2215+
/// synchronize data. Defaults to the value set in the app's entitlements.
2216+
public func attachMetadatabase(containerIdentifier: String? = nil) throws {
22322217
@Dependency(\.context) var context
22332218
let containerIdentifier =
22342219
containerIdentifier
@@ -2249,18 +2234,11 @@
22492234
"""
22502235
)
22512236
}
2252-
let url = try metadatabaseURL
2253-
?? URL.metadatabase(
2254-
databasePath: databasePath,
2255-
containerIdentifier: containerIdentifier
2256-
)
2237+
let url = try URL.metadatabase(
2238+
databasePath: databasePath,
2239+
containerIdentifier: containerIdentifier
2240+
)
22572241
let path = url.isInMemory ? url.absoluteString : url.path(percentEncoded: false)
2258-
if !url.isInMemory {
2259-
try FileManager.default.createDirectory(
2260-
at: url.deletingLastPathComponent(),
2261-
withIntermediateDirectories: true
2262-
)
2263-
}
22642242
let database: any DatabaseWriter =
22652243
url.isInMemory
22662244
? try DatabaseQueue(path: path)

0 commit comments

Comments
 (0)