|
75 | 75 | /// you do not want to be shareable with other users. |
76 | 76 | /// - containerIdentifier: The container identifier in CloudKit to synchronize to. If omitted |
77 | 77 | /// 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. |
80 | 78 | /// - defaultZone: The zone for all records to be stored in. |
81 | 79 | /// - startImmediately: Determines if the sync engine starts right away or requires an |
82 | 80 | /// explicit call to ``start()``. By default this argument is `true`. |
|
92 | 90 | tables: repeat (each T1).Type, |
93 | 91 | privateTables: repeat (each T2).Type, |
94 | 92 | containerIdentifier: String? = nil, |
95 | | - metadatabaseURL: URL? = nil, |
96 | 93 | defaultZone: CKRecordZone = CKRecordZone(zoneName: "co.pointfree.SQLiteData.defaultZone"), |
97 | 94 | startImmediately: Bool? = nil, |
98 | 95 | delegate: (any SyncEngineDelegate)? = nil, |
|
149 | 146 | ) |
150 | 147 | }, |
151 | 148 | userDatabase: userDatabase, |
152 | | - metadatabaseURL: metadatabaseURL, |
153 | 149 | logger: logger, |
154 | 150 | delegate: delegate, |
155 | 151 | tables: allTables, |
|
199 | 195 | ) |
200 | 196 | }, |
201 | 197 | userDatabase: userDatabase, |
202 | | - metadatabaseURL: metadatabaseURL, |
203 | 198 | logger: logger, |
204 | 199 | delegate: delegate, |
205 | 200 | tables: allTables, |
|
220 | 215 | SyncEngine |
221 | 216 | ) -> (private: any SyncEngineProtocol, shared: any SyncEngineProtocol), |
222 | 217 | userDatabase: UserDatabase, |
223 | | - metadatabaseURL: URL? = nil, |
224 | 218 | logger: Logger, |
225 | 219 | delegate: (any SyncEngineDelegate)?, |
226 | 220 | tables: [any SynchronizableTable], |
|
264 | 258 | self.defaultSyncEngines = defaultSyncEngines |
265 | 259 | self.userDatabase = userDatabase |
266 | 260 | 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( |
270 | 264 | databasePath: userDatabase.path, |
271 | 265 | containerIdentifier: container.containerIdentifier |
272 | 266 | ) |
273 | | - self.metadatabase = try defaultMetadatabase( |
274 | | - logger: logger, |
275 | | - url: resolvedMetadatabaseURL |
276 | 267 | ) |
277 | 268 | self.tablesByName = Dictionary( |
278 | 269 | uniqueKeysWithValues: self.tables.map { ($0.base.tableName, $0) } |
|
2220 | 2211 | /// |
2221 | 2212 | /// See <doc:PreparingDatabase> for more information on preparing your database. |
2222 | 2213 | /// |
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 { |
2232 | 2217 | @Dependency(\.context) var context |
2233 | 2218 | let containerIdentifier = |
2234 | 2219 | containerIdentifier |
|
2249 | 2234 | """ |
2250 | 2235 | ) |
2251 | 2236 | } |
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 | + ) |
2257 | 2241 | 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 | | - } |
2264 | 2242 | let database: any DatabaseWriter = |
2265 | 2243 | url.isInMemory |
2266 | 2244 | ? try DatabaseQueue(path: path) |
|
0 commit comments