With Cocoa how do i check that given file is owned by current user?
Given a file path how do i check that this file is owned by current user? Currently i managed to get:
[[[NSFileManager def开发者_开发技巧aultManager] 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?
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:
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
精彩评论