PDA

View Full Version : Changing file permissions




cea
Nov 11, 2009, 02:10 PM
Hi,
I just did a test to change file permissions. It works but it does not pop up the Authentication dialog.
Is there something wrong?
Thank you:

#import "untitled.h"

@implementation untitled
- (IBAction)myAction:(id)sender
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *path = @"/Users/cea/Desktop/test.zip";

// Set permissions to prohibit access from other users
NSDictionary *attr=[NSDictionary dictionaryWithObject:[NSNumber numberWithUnsignedLong:0777U] forKey:NSFilePosixPermissions];
[fileManager setAttributes:attr ofItemAtPath:path error:nil];
NSLog(@"0777 %@", path);
}

@end



chown33
Nov 11, 2009, 02:46 PM
First, if you own a file or folder, then you always have the ability to change its permissions. No authentication dialog is needed.

Second, changing the permissions to 0777 (octal) does not prohibit access by others. Quite the opposite: it grants read and write access to everyone. Anyone can read or write to the file. It also marks the file as executable, which is simply wrong for a zip file.

Why do you think 0777 will prohibit access from others? Please give the full name or URL of the reference or book you're reading this from.

cea
Nov 11, 2009, 03:21 PM
ohh the comment belongs to another test code which was here before. i just forgot to remove it.
Thank you for your info!