mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-08 22:33:26 +01:00
Verifies source’s identifier doesn’t match existing sources when adding
This commit is contained in:
@@ -283,13 +283,31 @@ private extension SourcesViewController
|
||||
AppManager.shared.fetchSource(sourceURL: url, dependencies: dependencies) { (result) in
|
||||
do
|
||||
{
|
||||
// Use @Managed before calling perform() to keep
|
||||
// strong reference to source.managedObjectContext.
|
||||
@Managed var source = try result.get()
|
||||
|
||||
DispatchQueue.main.async {
|
||||
self.showSourceDetails(for: source)
|
||||
let backgroundContext = DatabaseManager.shared.persistentContainer.newBackgroundContext()
|
||||
backgroundContext.perform {
|
||||
do
|
||||
{
|
||||
let predicate = NSPredicate(format: "%K == %@", #keyPath(Source.identifier), $source.identifier)
|
||||
if let existingSource = Source.first(satisfying: predicate, in: backgroundContext)
|
||||
{
|
||||
throw SourceError.duplicate(source, previousSourceName: existingSource.name)
|
||||
}
|
||||
|
||||
DispatchQueue.main.async {
|
||||
self.showSourceDetails(for: source)
|
||||
}
|
||||
|
||||
finish(.success(()))
|
||||
}
|
||||
catch
|
||||
{
|
||||
finish(.failure(error))
|
||||
}
|
||||
}
|
||||
|
||||
finish(.success(()))
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user