Verifies source’s identifier doesn’t match existing sources when adding

This commit is contained in:
Riley Testut
2023-05-11 18:51:09 -05:00
committed by Magesh K
parent bd3beb5983
commit f884d72a8b
3 changed files with 43 additions and 6 deletions

View File

@@ -365,8 +365,12 @@ extension AppManager
let action = await UIAlertAction(title: NSLocalizedString("Add Source", comment: ""), style: .default)
try await presentingViewController.presentConfirmationAlert(title: title, message: message, primaryAction: action)
// Wait for fetch to finish before saving context.
_ = try await fetchedSource
// Wait for fetch to finish before saving context to make
// sure there isn't already a source with this identifier.
let sourceExists = try await fetchedSource.isAdded
// This is just a sanity check, so pass nil for previousSourceName to keep code simple.
guard !sourceExists else { throw SourceError.duplicate(source, previousSourceName: nil) }
try await context.performAsync {
try context.save()