Re: Alias vs. Symbolic Link
Re: Alias vs. Symbolic Link
- Subject: Re: Alias vs. Symbolic Link
- From: email@hidden
- Date: Sat, 5 May 2001 16:15:29 -0700
On Saturday, May 5, 2001, at 03:50 PM, Steve Gehrman wrote:
>
Is there a difference between a symbolic link and a alias created in
>
the finder? I have some code that doesn't work with aliases created in
>
the finder.... Am I missing something? When I call this method with
>
an alias, the type returned is: NSFileTypeRegular.
Yes, there is a difference. An alias file is a file containing some
information pointing to another file. This information can include the
path to the source file, as well as other info to track the file if the
file is moved around by the user.
Use the following to resolve aliases (from the AppKit release notes):
#import <Carbon/Aliases.h>
NSString* ResolveAliasPath(NSString* path)
{
CFStringRef resolvedPath = nil;
CFURLRef url = CFURLCreateWithFileSystemPath(NULL /*allocator*/,
(CFStringRef)path, kCFURLPOSIXPathStyle, NO /*isDirectory*/);
if (url != NULL) {
FSRef fsRef;
if (CFURLGetFSRef(url, &fsRef)) {
Boolean targetIsFolder, wasAliased;
if (FSResolveAliasFile (&fsRef, true /*resolveAliasChains*/,
&targetIsFolder, &wasAliased) == noErr && wasAliased) {
CFURLRef resolvedurl = CFURLCreateFromFSRef(NULL
/*allocator*/, &fsRef);
if (resolvedurl != NULL) {
resolvedPath = CFURLCopyFileSystemPath(resolvedurl,
kCFURLPOSIXPathStyle);
CFRelease(resolvedurl);
}
}
}
CFRelease(url);
}
return resolvedPath != nil ? [(NSString*)resolvedPath autorelease] :
path;
}