2010

2009

2007

2006

2005

Symbolic Trouble

Entry published jul 13 2005

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?

Next: It's Too Bad

comments