[Path Config] Remove exact items by token id

Should use the exact token object to remove them, rather than doing a
path comparison.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
xcode15
Christopher Snowhill 2022-07-06 00:02:34 -07:00
parent 1fb636ffd2
commit aa7eb52231
3 changed files with 17 additions and 24 deletions

View File

@ -36,9 +36,9 @@
- (IBAction)deleteSelectedPaths:(id)sender {
NSArray *selectedObjects = [sandboxPathBehaviorController selectedObjects];
if(selectedObjects && [selectedObjects count]) {
NSArray *paths = [selectedObjects valueForKey:@"path"];
for(NSString *path in paths) {
[sandboxPathBehaviorController removePath:path];
NSArray *tokens = [selectedObjects valueForKey:@"token"];
for(id token in tokens) {
[sandboxPathBehaviorController removeToken:token];
}
}
}

View File

@ -12,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface SandboxPathBehaviorController : NSArrayController
- (void)addUrl:(NSURL *)url;
- (void)removePath:(NSString *)path;
- (void)removeToken:(id)token;
- (void)removeStaleEntries;
- (BOOL)matchesPath:(NSURL *)url;

View File

@ -73,36 +73,29 @@
}
}
- (void)removePath:(NSString *)path {
- (void)removeToken:(id)token {
NSPersistentContainer *pc = [NSClassFromString(@"PlaylistController") sharedPersistentContainer];
NSArray *objects = [[self arrangedObjects] copy];
BOOL updated = NO;
for(NSDictionary *obj in objects) {
if([[obj objectForKey:@"path"] isEqualToString:path]) {
if([[obj objectForKey:@"token"] isEqualTo:token]) {
[self removeObject:obj];
[pc.viewContext deleteObject:token];
updated = YES;
break;
}
}
NSPersistentContainer *pc = [NSClassFromString(@"PlaylistController") sharedPersistentContainer];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"path == %@", path];
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"SandboxToken"];
request.predicate = predicate;
NSError *error = nil;
NSArray *results = [pc.viewContext executeFetchRequest:request error:&error];
if(results && [results count] > 0) {
for(SandboxToken *token in results) {
[pc.viewContext deleteObject:token];
if(updated) {
NSError *error;
[pc.viewContext save:&error];
if(error) {
ALog(@"Error deleting bookmark: %@", [error localizedDescription]);
}
}
[pc.viewContext save:&error];
if(error) {
ALog(@"Error deleting bookmark: %@", [error localizedDescription]);
}
}
- (void)removeStaleEntries {