On Fri, 15 Apr 2011 11:22:45 -0500, Ken Thomases said:

>>> Yes.  Bookmark data is the modern replacement for alias records.  The
>>> new bookmark APIs are backward compatible with aliases, including alias
>>> files.  See the documentation for +[NSURL
>>> bookmarkDataWithContentsOfURL:error:].  You'd follow that with -
>>> URLByResolvingBookmarkData:options
>:relativeToURL:bookmarkDataIsStale:error:.
>>
>> Yeah, that works, but is not easy.
>
>Eh, seems easy enough to me.

I can't agree.  _This_ is easy:

url = [url URLByResolvingSymlinksInPath];

_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;
}       

Especially since, again, the Mac UI doesn't even let you create
symlinks, but does let you create aliases.  It seems to me the symlink
case should be the convoluted case.

But, as you say, category methods are a nice thing to have!

Thanks,

--
____________________________________________________________
Sean McBride, B. Eng                 [email protected]
Rogue Research                        www.rogue-research.com
Mac Software Developer              Montréal, Québec, Canada


_______________________________________________

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