Re: FSIsAliasFile deprecated - typeOfFile is slow
Re: FSIsAliasFile deprecated - typeOfFile is slow
- Subject: Re: FSIsAliasFile deprecated - typeOfFile is slow
- From: "Gary L. Wade" <email@hidden>
- Date: Sat, 28 Nov 2015 09:26:40 -0800
Extended attributes aren't going away, and current alias files aren't going away; those exist on the latest OS. Try this and getResourceValue: to see if there's any significant difference, and if you eventually do need the alias data you might also try the bookmark API on the file (check to be sure nil is returned for a non-alias), especially when you scale up to a large file set, and if my suggested wrapper around the BSD layer is fastest, write a http://bugreport.apple.com asking Apple to add it as a blessed API based on performance reasons and your need (besides the method result of BOOL, it should also return an NSError in case the file doesn't exist). After all, what is Cocoa but wrappers around lower levels? Someone eventually "gets their hands dirty."
If I need to revisit the app that needs such a solution, I'll also report it, and maybe it'll make it into OS X 10.12. Some things do get added this way.
--
Gary L. Wade (Sent from my iPad)
http://www.garywade.com/
> On Nov 28, 2015, at 7:59 AM, Leonardo <email@hidden> wrote:
>
> Hi Gary,
> Thank you for your low level fine solution. Anyway, I'm afraid that Apple
> changes the alias-rule and this method will not work longer. Do you have a
> solution at a upper level? Or may I be 100% sure that Apple will never
> change this rule?
>
> Regards
> -- Leonardo
>
>
>> Da: "Gary L. Wade" <email@hidden>
>> Data: Fri, 27 Nov 2015 16:48:43 -0800
>> A: Leonardo <email@hidden>
>> Cc: <email@hidden>
>> Oggetto: Re: FSIsAliasFile deprecated - typeOfFile is slow
>>
>> Although I have experience with your performance hit, one solution I would
>> probably try when it becomes important again for me would be to do this:
>>
>> 1. Using the BSD layer of APIs, see if the file (alias files are regular files
>> from a statfs call, even folder aliases) has an extended attribute named
>> "com.apple.FinderInfo". If it does not, it is not an alias file.
>> 2. If the extended attribute does exist and is of length 32 bytes (or more
>> although doubtful this would ever change), you might have an alias file. If
>> less, just say no assuming corruption.
>> 3. Get the bytes of the extended attribute and examine the byte at index 8
>> (bytes[8]) to see if its high bit is set (bytes[8] | 0x80). If so, you have an
>> alias; if not, you don't.
>> 4. Add this logic in an appropriate category method (to keep this Cocoa).
>>
>> For reference, look up ATTR_CMN_FNDRINFO, xattr, Finder.h. Note this extended
>> attribute has its integers in big-endian format. You might also look at the
>> fileType parameter of the CoreServices FileInfo that maps the first 16 bytes,
>> but that requires more checking.
>> --
>> Gary L. Wade (Sent from my iPhone)
>> http://www.garywade.com/
>>
>>> On Nov 27, 2015, at 2:00 PM, Leonardo <email@hidden> wrote:
>>>
>>> Hi,
>>> I actually detect whether a file is an alias this way:
>>> I use a NSString category where self is the filePath.
>>>
>>> - (BOOL)IsAliasOld
>>> {
>>> FSRef sourceRef;
>>>
>>> OSErr err = [self GetFSRef:&sourceRef];
>>> if(err) return NO;
>>>
>>> Boolean isFSDirectory, aliasFileFlag;
>>>
>>> err = FSIsAliasFile(&sourceRef, &aliasFileFlag, &isFSDirectory);
>>> if(err) return NO;
>>> else return aliasFileFlag;
>>> }
>>>
>>> - (OSErr)GetFSRef:(FSRef*)sourceRef
>>> {
>>> const char *cSrcPath = [[NSFileManager defaultManager]
>>> fileSystemRepresentationWithPath:self];
>>> if(cSrcPath == 0 || *cSrcPath == _NUL) return -1;
>>>
>>> OSErr err = FSPathMakeRefWithOptions((UInt8*)cSrcPath,
>>> kFSPathMakeRefDoNotFollowLeafSymlink, sourceRef, NULL);
>>> return err;
>>> }
>>>
>>>
>>> Since FSIsAliasFile is deprecated (I compile for 10.9) I would now use
>>>
>>> - (BOOL)IsAliasNew
>>> {
>>> NSString *type = [[NSWorkspace sharedWorkspace] typeOfFile:self
>>> error:nil];
>>> return [type isEqualToString:@"com.apple.alias-file"];
>>> }
>>>
>>> The problem is that the IsAliasNew method is 3.7 times slower than the
>>> IsAliasOld method. Do you know a way to accomplish that with a faster
>>> method?
>
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden