Re: Aliases & fileAttributesAtPath:
Re: Aliases & fileAttributesAtPath:
- Subject: Re: Aliases & fileAttributesAtPath:
- From: Chris Hanson <email@hidden>
- Date: Sat, 13 Oct 2001 22:46:17 -0500
At 1:26 PM +0100 10/12/01, Ondra Cada wrote:
They would, on the other hand, break almost anything what used to work
originally, from shell scripts through posix or BSD API tools to Cocoa
applications.
Soft and hard links though work quite properly with all that.
Cocoa doesn't default to resolving aliases in the middle of paths?
That's bogus. Just points to more need to update Cocoa to handle
FSRefs and AliasRecords. Of course, you should never actually be
*storing* paths as persistent file references, so neither you nor
your users should actually encounter such a situation in common use.
(If you want to store a persistent reference to a file, download and
use BDAlias: <
http://bdistributed.com/Projects/BDAlias/index.html>
Or write your own and just store alias records as NSData.)
-- Chris
PS - Here's an untested, never compiled method that will resolve an
alias file at a particular path and return to you a new path.
There's no warranty, no guarantee, and it's 100% public-domain. (Can
anyone tell me if CFURLRef and NSURL are bridged? That would be
really convenient.)
- (NSString *)resolveAliasAtPath:(NSString *)aliasFullPath
{
NSString *outString = nil;
CFURLRef url = NULL;
Boolean success = false;
FSRef aliasRef;
OSErr anErr = noErr;
Boolean targetIsFolder;
Boolean wasAliased;
url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
aliasFullPath,
kCFURLPOSIXPathStyle,
false);
if (url == NULL) {
return nil;
}
success = CFURLGetFSRef(url, &aliasRef);
CFRelease(url);
if (success == false) {
return nil;
}
anErr = FSResolveAliasFile(&aliasRef, true, &targetIsFolder, &wasAliased);
if (anErr != noErr) {
return nil;
}
url = CFURLCreateFromFSREf(kCFAllocatorDefault, &aliasRef);
if (url == NULL) {
return nil;
}
outString = (NSString *)CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);
CFRelease(url);
return [outString autorelease];
}