On Apr 15, 2011, at 11:10, Sean McBride wrote:

> _this_ is a PITA:
> 
> - (NSURL*)URLByResolvingSymlinksAndAliases
> {
>       NSURL* resultURL = [self URLByResolvingSymlinksInPath];
>       
>       NSError* error = nil;
>       NSNumber* isAliasFile = nil;
>       BOOL success = [resultURL getResourceValue:&isAliasFile
>                                                                               
> forKey:NSURLIsAliasFileKey
>                                                                               
>  error:&error];
>       if (success && [isAliasFile boolValue])
>       {
>               NSData* bookmarkData = [NSURL 
> bookmarkDataWithContentsOfURL:resultURL
>                                                                               
>                                           error:&error];
>               if (bookmarkData)
>               {
>                       BOOL isStale = NO;
>                       NSURLBookmarkResolutionOptions options =
> (NSURLBookmarkResolutionWithoutUI |
>                                                                               
>                           NSURLBookmarkResolutionWithoutMounting);      
>                       
>                       NSURL* resolvedURL = [NSURL 
> URLByResolvingBookmarkData:bookmarkData
>                                                                               
>                                    options:options
>                                                                               
>                          relativeToURL:nil
>                                                                               
>            bookmarkDataIsStale:&isStale
>                                                                               
>                                          error:&error];
>                       if (resolvedURL)
>                       {
>                               resultURL = resolvedURL;
>                       }
>               }
>       }
>       
>       return resultURL;
> }     

I'll ask the dumb question: what happens if you invoke 
bookmarkDataWithContentsOfURL on a non-alias file? If it correctly detects an 
error, your PITA code could be reduced to:

> - (NSURL*)URLByResolvingSymlinksAndAliases
> {
>       NSURL* resultURL = [self URLByResolvingSymlinksInPath];
>       
>       NSData* bookmarkData = [NSURL bookmarkDataWithContentsOfURL:resultURL 
> error: NULL];
>       if (bookmarkData)
>       {
>               NSURL* resolvedURL = [NSURL 
> URLByResolvingBookmarkData:bookmarkData
>                                                                       
> options:(NSURLBookmarkResolutionWithoutUI | 
> NSURLBookmarkResolutionWithoutMounting)
>                                                                       
> relativeToURL:nil
>                                                                       
> bookmarkDataIsStale:NULL
>                                                                       
> error:NULL];
>               if (resolvedURL)
>                       resultURL = resolvedURL;
> 
>       }
>       
>       return resultURL;
> }     


which is a *lot* less unpleasant.


_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to