Sandbox: Invalidate dead network shares faster

This should solve the endless waiting people were experiencing.

Fixes #392

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This commit is contained in:
Christopher Snowhill 2025-06-26 03:32:40 -07:00
parent 7774c17efa
commit 41780e88d0
2 changed files with 31 additions and 2 deletions

View file

@ -45,10 +45,27 @@
if(results && [results count] > 0) {
for(SandboxToken *token in results) {
BOOL isDisconnected = NO;
BOOL isStale = YES;
NSError *err = nil;
NSURL *bookmarkUrl = [NSURL URLByResolvingBookmarkData:token.bookmark options:NSURLBookmarkResolutionWithSecurityScope relativeToURL:nil bookmarkDataIsStale:&isStale error:&err];
[self addObject:@{ @"path": token.path, @"valid": ((!bookmarkUrl || isStale) ? NSLocalizedPrefString(@"ValidNo") : NSLocalizedPrefString(@"ValidYes")), @"isFolder": @(token.folder), @"token": token }];
{
NSDictionary *dict = [NSURL resourceValuesForKeys:@[NSURLVolumeURLKey] fromBookmarkData:token.bookmark];
if(dict) {
NSURL *volumeUrl = dict[NSURLVolumeURLKey];
if(volumeUrl && [volumeUrl isFileURL] && [volumeUrl path]) {
if(![[NSFileManager defaultManager] fileExistsAtPath:[volumeUrl path]]) {
isDisconnected = YES;
}
}
}
}
if(!isDisconnected) {
NSURL *bookmarkUrl = [NSURL URLByResolvingBookmarkData:token.bookmark options:NSURLBookmarkResolutionWithSecurityScope relativeToURL:nil bookmarkDataIsStale:&isStale error:&err];
[self addObject:@{ @"path": token.path, @"valid": ((!bookmarkUrl || isStale) ? NSLocalizedPrefString(@"ValidNo") : NSLocalizedPrefString(@"ValidYes")), @"isFolder": @(token.folder), @"token": token }];
} else {
[self addObject:@{ @"path": token.path, @"valid": NSLocalizedPrefString(@"ValidNo"), @"isFolder": @(token.folder), @"token": token }];
}
}
}
}

View file

@ -192,6 +192,18 @@ static SandboxBroker *kSharedSandboxBroker = nil;
}
}];
if(ret) {
NSDictionary *dict = [NSURL resourceValuesForKeys:@[NSURLVolumeURLKey] fromBookmarkData:ret.token.bookmark];
if(dict) {
NSURL *volumeUrl = dict[NSURLVolumeURLKey];
if(volumeUrl && [volumeUrl isFileURL] && [volumeUrl path]) {
if(![[NSFileManager defaultManager] fileExistsAtPath:[volumeUrl path]]) {
return nil;
}
}
}
}
if(ret) {
BOOL isStale;
NSError *err = nil;