Symbolic Trouble

Lately I’ve been doing file system work in cocoa and I was using NSFileManager, but that quickly got out of hand as NSFileManager is lacking in regards to symbolic links. So, I factored out the often used code and created a class which uses FSRefs internally. However, I’ve since had a problem: I don’t want to resolve symbolic links but almost every method out there automatically resolves them. I’ve been able to work around many of the methods that resolve symbolic links by using Carbon, but there are still a few pesky problems. The biggest one is: How do you determine your read/write privileges for a symbolic link and not what the link points to? I’ve played around with a number of different ways to get the access privileges, here’s of taste of what I’ve tried:

[NSFileManager isReadableAtPath:]
This is no good because it automatically resolves links

access() function
Also a no go because it automatically resolves symbolic links.

FSGetUserPrivilegesPermissions();
This one seems fairly promising, if only I could get it to work right. It’s a function from MoreFilesX that goes out to the files/folders catalog info and retrieves/creates a userPrivileges int which contains what the current user has access to. However, it is not reliable whatsoever. It frequently tells me that directories which are marked no access are read only? So maybe it’s something I’m doing wrong, and it looks to me like I’m not the first to experience this. So what is going on? Here’s a snip of code:

OSErr err;
UInt8 userPrivileges;
bool isReadable;
err = FSGetUserPrivilegesPermissions( &ref, &userPrivileges, NULL );
if( err != 0 )
{
//error stuff
}
isReadable = !( userPrivileges & kioACUserNoSeeFilesMask );

Any one know another way besides reading the file permissions and checking if the user is part of that group and etc?


2 Responses to “Symbolic Trouble”  

  1. 1 Hoa

    NSFileManager:
    - (NSDictionary *)fileAttributesAtPath:(NSString *)path traverseLink:(BOOL)flag
    with traverseLink:NO should do it for you.

  2. 2 Michael Grubb

    Symbolic links don’t actually have access permissions of their own, they use the permissions of the entity that they point to. On some platforms, all symlinks are created 777 with root/0 ownerships regardless of who created them or what they point to, though if you tried to to write to a file pointed to by that symlink that you wouldn’t have normal access to you would still get permission denied. This is a long way of saying, check the permissions of the canonical path name, to determine the permissions of the non-resolved path.

Leave a Reply