Skip to content

Commit 7a80d25

Browse files
authored
[Collections] Removed local package collection comes back alive (#3617)
Steps to reproduce: 1. Add a local collection 2. Delete the collection **file** on local disk 3. Refresh collections 4. The unavailable local collection is back! This is caused by us not deleting unavailable/invalid collections from storage when refresh fails. rdar://80388968
1 parent ba74c9d commit 7a80d25

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Sources/PackageCollections/PackageCollections.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,16 +454,16 @@ public struct PackageCollections: PackageCollectionsProtocol {
454454
private func refreshCollectionFromSource(source: PackageCollectionsModel.CollectionSource,
455455
trustConfirmationProvider: ((PackageCollectionsModel.Collection, @escaping (Bool) -> Void) -> Void)?,
456456
callback: @escaping (Result<Model.Collection, Error>) -> Void) {
457-
if let errors = source.validate()?.errors() {
458-
return callback(.failure(MultipleErrors(errors)))
459-
}
460457
guard let provider = self.collectionProviders[source.type] else {
461458
return callback(.failure(UnknownProvider(source.type)))
462459
}
463460
provider.get(source) { result in
464461
switch result {
465462
case .failure(let error):
466-
callback(.failure(error))
463+
// Remove the unavailable/invalid collection (if previously saved) from storage before calling back
464+
self.storage.collections.remove(identifier: PackageCollectionsModel.CollectionIdentifier(from: source)) { _ in
465+
callback(.failure(error))
466+
}
467467
case .success(let collection):
468468
// If collection is signed and signature is valid, save to storage. `provider.get`
469469
// would have failed if signature were invalid.

0 commit comments

Comments
 (0)