13.07.2015 Views

Beginning Objective-C pdf - EBook Free Download

Beginning Objective-C pdf - EBook Free Download

Beginning Objective-C pdf - EBook Free Download

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 5: Using the Filesystem 115which returns an instance of NSFileSecurity. The one hitch to this otherwise nice API is thatthe NSFileSecurity class defines no methods or properties at all. Instead, to make use of it youhave to cast it to its toll-free bridged CoreFoundation counterpart, CFFileSecurityRef. Havingdone so, you’ll be able to make use of it to read and potentially modify the file’s user/group/otherPOSIX permissions and any access control lists, although the latter uses an even lower-levelplain C API, which is beyond the scope of this book. For your delight and edification, however,I respectfully submit Listing 5-5, which shows how to list all the relevant information from anNSFileSecurity object.Listing 5-5. Using NSFileSecurityNSFileSecurity * sec = . . .;CFFileSecurityRef cfSec = (__bridge CFFileSecurityRef)sec;CFUUIDRef tmpUUID = NULL;uid_t owner = (uid_t)-1;gid_t group = (gid_t)-1;mode_t mode = 0;acl_t acl = NULL;if ( CFFileSecurityCopyOwnerUUID(cfSec, &tmpUUID) )NSLog(@"Owner UUID = %@", CFBridgingRelease(tmpUUID));if ( CFFileSecurityCopyGroupUUID(cfSec, &tmpUUID) )NSLog(@"Group UUID = %@", CFBridgingRelease(tmpUUID));if ( CFFileSecurityGetOwner(cfSec, &owner) )NSLog(@"Owner = %s (%u)", getpwuid(owner)->pw_name, owner);if ( CFFileSecurityGetGroup(cfSec, &group) )NSLog(@"Group = %s (%u)", getgrgid(group)->gr_name, group);if ( CFFileSecurityGetMode(cfSec, &mode) )NSLog(@"Mode = %#o", mode);if ( CFFileSecurityCopyAccessControlList(cfSec, &acl) ){char * aclStr = acl_to_text(acl, NULL);NSLog(@"ACL = %s", aclStr);acl_free(aclStr);acl_free(acl);}File Reference URLsAlong with path-based URLs, a local file or folder can also be referenced using a special type offile URL known as a file reference URL. The theory goes like this: a path-based URL specifiesa location in terms of a path through various folders to a location. The item at that locationis known by the filesystem through a unique identifier. When that file moves elsewhere or isrenamed, its identifier doesn’t change, nor does the storage allocated for that file on disk.The only change that takes place is that the reference to it in its current parent folder is removed,and a similar reference is placed into its new parent folder. A file reference URL identifies the fileby its reference number rather than its position in the folder hierarchy, meaning that it doesn’tmatter where the file resides, or whether it moves—as long as it exists, it can be found.www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!