From 54ccb9611ef1bb323e3c3292f7b2d76b0e5ba2f5 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Tue, 20 Sep 2022 13:12:47 -0500 Subject: [PATCH] =?UTF-8?q?Fixes=20=E2=80=9Cerror=20migrating=20persistent?= =?UTF-8?q?=20store=E2=80=9D=20issue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We now set AppVersion.sourceID during migration, which fixes AppVersion entries conflicting across different Sources if multiple contain the same app + version. --- .../Policies/StoreApp10ToStoreApp11Policy.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/AltStoreCore/Model/Migrations/Policies/StoreApp10ToStoreApp11Policy.swift b/AltStoreCore/Model/Migrations/Policies/StoreApp10ToStoreApp11Policy.swift index 71ee1f7c..ead50098 100644 --- a/AltStoreCore/Model/Migrations/Policies/StoreApp10ToStoreApp11Policy.swift +++ b/AltStoreCore/Model/Migrations/Policies/StoreApp10ToStoreApp11Policy.swift @@ -16,6 +16,11 @@ fileprivate extension NSManagedObject return bundleID } + var storeAppSourceID: String? { + let sourceID = self.value(forKey: #keyPath(StoreApp.sourceIdentifier)) as? String + return sourceID + } + var storeAppVersion: String? { let version = self.value(forKey: #keyPath(StoreApp._version)) as? String return version @@ -55,6 +60,7 @@ fileprivate extension NSManagedObject downloadURL: URL, size: Int64, appBundleID: String, + sourceID: String, in context: NSManagedObjectContext) -> NSManagedObject { let appVersion = NSEntityDescription.insertNewObject(forEntityName: AppVersion.entity().name!, into: context) @@ -64,6 +70,7 @@ fileprivate extension NSManagedObject appVersion.setValue(downloadURL, forKey: #keyPath(AppVersion.downloadURL)) appVersion.setValue(size, forKey: #keyPath(AppVersion.size)) appVersion.setValue(appBundleID, forKey: #keyPath(AppVersion.appBundleID)) + appVersion.setValue(sourceID, forKey: #keyPath(AppVersion.sourceID)) return appVersion } } @@ -76,6 +83,7 @@ class StoreApp10ToStoreApp11Policy: NSEntityMigrationPolicy try super.createDestinationInstances(forSource: sInstance, in: mapping, manager: manager) guard let appBundleID = sInstance.storeAppBundleID, + let sourceID = sInstance.storeAppSourceID, let version = sInstance.storeAppVersion, let versionDate = sInstance.storeAppVersionDate, // let versionDescription = sInstance.storeAppVersionDescription, // Optional @@ -95,6 +103,7 @@ class StoreApp10ToStoreApp11Policy: NSEntityMigrationPolicy downloadURL: downloadURL, size: Int64(size), appBundleID: appBundleID, + sourceID: sourceID, in: context) destinationStoreApp.setStoreAppLatestVersion(appVersion)