[Path Config] Properly prune the database

When cleaning up the path list, actually remove the pruned entries from
the Core Data storage, so they don't end up resolving to broken
bookmarks in the player, breaking playback on migrated configurations.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
lastfm
Christopher Snowhill 2022-07-05 23:47:05 -07:00
parent 0e2bfeb671
commit d03fb11f4c
1 changed files with 11 additions and 0 deletions

View File

@ -106,9 +106,20 @@
}
- (void)removeStaleEntries {
BOOL updated = NO;
NSPersistentContainer *pc = [NSClassFromString(@"PlaylistController") sharedPersistentContainer];
for(NSDictionary *entry in [[self arrangedObjects] copy]) {
if([[entry objectForKey:@"valid"] isEqualToString:NSLocalizedPrefString(@"ValidNo")]) {
[self removeObject:entry];
[pc.viewContext deleteObject:[entry objectForKey:@"token"]];
updated = YES;
}
}
if(updated) {
NSError *error;
[pc.viewContext save:&error];
if(error) {
ALog(@"Error saving after removing stale bookmarks: %@", [error localizedDescription]);
}
}
}