Permissions woes
Permissions woes
- Subject: Permissions woes
- From: Clark Mueller <email@hidden>
- Date: Fri, 20 Sep 2002 18:24:00 -0600
Hi folks,
I have a mess of code for setting permissions that isn't working in
quite the method I am wanting it to. What happens is that SETTING
permissions bits, adding them to the current permissions, works fine.
It's when I try to clear the bit in question (in the code below, the
group write bit) that things don't work as I expected. What happens is
that the bit I should be taking away becomes the ONLY bit SET. This led
me to think that I'm using the wrong bit operator, but I've tried with
both exclusive OR and inclusive OR, with no luck... Do I need to be
ANDing it to clear it? Am I totally an idiot ( me thinks so ;) )?
Curiously, I made it work properly with setting the write bit, which is
using the same code as below, except with the group write constant.
Anyone have any idea what's up? Here's an example of the code:
-----
- (int)setGroupExecuteState:(BOOL)state forFiles:(NSArray *)files{
int i = 0;
int failures = 0;
NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
long perms = 0;
for( ; i < [files count]; i++ ){
if( [ig fileExists:currentObject] ){
attrs = [NSMutableDictionary
dictionaryWithDictionary:[[NSFileManager defaultManager]
fileAttributesAtPath:currentObject traverseLink:NO]];
perms = [[attrs objectForKey:NSFilePosixPermissions] longValue];
if( state )
perms |= 0000010;
else
perms ^= g_x; //g_x constant = 0000010
[attrs setObject:[NSNumber numberWithLong:perms]
forKey:NSFilePosixPermissions];
if( ![[NSFileManager defaultManager]
changeFileAttributes:[NSDictionary dictionaryWithDictionary:attrs]
atPath:currentObject] ){
failures++;
}
}
}
return failures;
}
-----
TIA,
Clark
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.