views:

30

answers:

2

Given a file path how do i check that this file is owned by current user? Currently i managed to get:

[[[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:outError] fileOwnerAccountID];

Which return NSNumber*. But i can't seem to google for how to get current user account id to compare it with. Besides all this looks messy, there seem to be a better way to do it, no?

A: 

Instead of

fileOwnerAccountID

try

fileOwnerAccountName

I'm new here, and if there's a reason this won't work maybe I've missed it. I'm not near my mac to test.

Hope this helps

bsrblake
There is also a function NSUserName that should return the current user's account name. Documentation:http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Functions/Reference/reference.html#//apple_ref/doc/uid/20000055-SW1
bsrblake
+1  A: 

You can get the current user's id with getuid().

Presumably the reason there's no single-call way of getting the information you want is that it's uncommon for a program to care whether the user owns a file; OS X, like UNIX in general, is more about permissions than ownership, so usually you'd use calls like isWritableFileAtPath: or isDeletableFileAtPath:

smorgan