Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

AndyCodez

macrumors regular
Original poster
Aug 6, 2009
187
0
I created a Directory for my application via code. I can write just fine to the new folder, but it is not allowing me to retrieve a listing of documents in the folder. aka contentsOfDirectoryAtPath

This is the error i get when trying to get the contents:
NSCocoaErrorDomain 257 {
NSFilePath = "/var/mobile/Applications/13E92A6C-AB08-4D7F-A19C-D6C66BA2A67C/Documents/Audio";
NSUnderlyingError = Error Domain=NSPOSIXErrorDomain Code=13 "Operation could not be completed. Permission denied";

This is how i set up the folder to be created

Code:
			NSMutableDictionary *directory = [[NSMutableDictionary alloc] init];
			[directory setValue:[NSNumber numberWithBool:NO] forKey:NSFileAppendOnly];
			[directory setValue:0 forKey:NSFileBusy];
			[directory setValue:[NSDate date] forKey:NSFileCreationDate];
			[directory setValue:@"User" forKey:NSFileOwnerAccountName];
			[directory setValue:@"Users" forKey:NSFileGroupOwnerAccountName];
			[directory setValue:[NSNumber numberWithInt:122] forKey:NSFileDeviceIdentifier];
			[directory setValue:0 forKey:NSFileExtensionHidden];
			[directory setValue:[NSNumber numberWithLong:23432] forKey:NSFileGroupOwnerAccountID];
			//[directory setValue:[NSNumber numberWithLong:3342] forKey:NSFileHFSCreatorCode];
			//[directory setValue:[NSNumber numberWithLong:3423] forKey:NSFileHFSTypeCode];
			[directory setValue:[NSNumber numberWithBool:YES] forKey:NSFileImmutable];
			[directory setValue:[NSDate date] forKey:NSFileModificationDate];
			[directory setValue:[NSNumber numberWithLong:89798] forKey:NSFilePosixPermissions];
			[directory setValue:[NSNumber numberWithLong:234] forKey:NSFileReferenceCount];
			[directory setValue:NSFileSystemFreeSize forKey:NSFileSize];
			[directory setValue:[NSNumber numberWithLong:5] forKey:NSFileSystemFileNumber];
			[directory setValue:NSFileTypeDirectory forKey:NSFileType];
			[fs createDirectoryAtPath:_documents_folder_audio withIntermediateDirectories:NO attributes:directory error:&err];

Just wondering if someone sees something I missed when setting this new folder up.

I know some of the values are not what they "should" be, I looked at the documentation on the apple site and it did not do too good of a job explaining how to get these values.
 
Code:
[directory setValue:[NSNumber numberWithLong:89798] forKey:NSFilePosixPermissions];

89798 doesn't correspond to any set of POSIX permissions I've ever seen.

89798 is equal to octal 257306. The lower-level code code is grabbing the lowest 3 or 4 triplets (sticky bits!) which, in this case, is 011 000 110 or 0306. This means you'll be setting the permissions to:
Owner -> -wx (which is why you can write but not read)
Group -> ---
World -> rw-

The easiest thing would be to just specify the actual permissions you want in octal instead of decimal (ie 0755, 0666, etc). I'm relatively sure just doing the following will yield the right behavior:
Code:
[fs     createDirectoryAtPath: _documents_folder_audio
  withIntermediateDirectories: NO
                   attributes: nil
                        error: &err];

Also, you probably shouldn't mess with the following keys unless you REALLY know what you're doing. The system most likely has safeguards to prevent the setting of bad/conflicting values but I'd be wary just the same, you could run into some nasty undefined (or unexpected!) behavior:
NSFileAppendOnly
NSFileBusy
NSFileDeviceIdentifier
NSFileGroupOwnerAccountID
NSFileGroupOwnerAccountName
NSFileHFSCreatorCode //Useless on a folder
NSFileHFSTypeCode //Useless on a folder
NSFileImmutable
NSFileModificationDate
NSFileOwnerAccountName
NSFileReferenceCount
NSFileSize
NSFileSystemFileNumber
 
_documents_folder_audio is just a string with the path that I want it to be created. That works fine. But I will look how Guiyon said to do it, I wasn't to sure about the values to be specified for some of the keys. The documentation did not go into that much detail as how to specify these things correctly.

- Edit: Guiyon was right just running it without the attributes worked. Thank you! I feel like an idiot lol. I couldn't even delete the one I had previously created, I imagine because I screwed up the permissions on it.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.