Reputation: 11352
Assignment of NSFileOwnerAccountName
and NSFileGroupOwnerAccountName
does not work? The directory created defaults to my account coderama
and the group staff
.
NSFileManager *fileManager = [NSFileManager defaultManager];
NSMutableDictionary *attr = [NSMutableDictionary dictionary];
[attr setObject:@"root" forKey:NSFileOwnerAccountName];
[attr setObject:@"wheel" forKey:NSFileGroupOwnerAccountName];
[attr setObject:[NSNumber numberWithInt:0755] forKey:NSFilePosixPermissions];
[fileManager createDirectoryAtPath:dir withIntermediateDirectories:TRUE attributes:attr error:&error];
Upvotes: 0
Views: 857
Reputation: 46020
It's highly likely that without authorization, you will be unable to create anything owned by root. However, assuming you do have authorization…
The docs don't mention this restriction specifically for createDirectoryAtPath:withIntermediateDirectories:attributes:
, but for the related method setAttributes:ofItemAtPath:error:
, you can't use NSFileOwnerAccountName
or NSFileGroupOwnerAccountName
. You must use the account ID instead, with NSFileOwnerAccountID
and NSFileGroupOwnerAccountID
. If you use the …Name
-based keys, they are ignored.
It may be that createDirectoryAtPath:withIntermediateDirectories:attributes:
also has this restriction. I would try setting IDs instead of names, which I suspect will work.
Upvotes: 2