From 0247c50650bf5eb90e107dda84f21208953e180d Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 30 Nov 2022 21:35:52 -0500 Subject: [PATCH] Fix invalid names being used for persistent store --- Tusker/CoreData/MastodonCachePersistentStore.swift | 2 +- Tusker/LocalData.swift | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Tusker/CoreData/MastodonCachePersistentStore.swift b/Tusker/CoreData/MastodonCachePersistentStore.swift index e8846675..2fc5938c 100644 --- a/Tusker/CoreData/MastodonCachePersistentStore.swift +++ b/Tusker/CoreData/MastodonCachePersistentStore.swift @@ -53,7 +53,7 @@ class MastodonCachePersistentStore: NSPersistentContainer { storeDescription.type = NSInMemoryStoreType persistentStoreDescriptions = [storeDescription] } else { - super.init(name: "\(accountInfo!.id)_cache", managedObjectModel: MastodonCachePersistentStore.managedObjectModel) + super.init(name: "\(accountInfo!.persistenceKey)_cache", managedObjectModel: MastodonCachePersistentStore.managedObjectModel) } loadPersistentStores { (description, error) in diff --git a/Tusker/LocalData.swift b/Tusker/LocalData.swift index ba4a7e89..4da80d77 100644 --- a/Tusker/LocalData.swift +++ b/Tusker/LocalData.swift @@ -208,6 +208,12 @@ extension LocalData { 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) { hasher.combine(id) }