Fix invalid names being used for persistent store

This commit is contained in:
Shadowfacts 2022-11-30 21:35:52 -05:00
parent eca06cb14a
commit 0247c50650
2 changed files with 7 additions and 1 deletions

View File

@ -53,7 +53,7 @@ class MastodonCachePersistentStore: NSPersistentContainer {
storeDescription.type = NSInMemoryStoreType storeDescription.type = NSInMemoryStoreType
persistentStoreDescriptions = [storeDescription] persistentStoreDescriptions = [storeDescription]
} else { } else {
super.init(name: "\(accountInfo!.id)_cache", managedObjectModel: MastodonCachePersistentStore.managedObjectModel) super.init(name: "\(accountInfo!.persistenceKey)_cache", managedObjectModel: MastodonCachePersistentStore.managedObjectModel)
} }
loadPersistentStores { (description, error) in loadPersistentStores { (description, error) in

View File

@ -208,6 +208,12 @@ extension LocalData {
self.accessToken = accessToken self.accessToken = accessToken
} }
/// A filename-safe string for this account
var persistenceKey: String {
// slashes are not allowed in the persistent store coordinator name
id.replacingOccurrences(of: "/", with: "_")
}
func hash(into hasher: inout Hasher) { func hash(into hasher: inout Hasher) {
hasher.combine(id) hasher.combine(id)
} }