Changing file permissions

Discussion in 'Mac Programming' started by cea, Nov 11, 2009.

  1. cea
    macrumors newbie

    Joined:
    Oct 26, 2009
    #1
    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:

    PHP:
    #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:0777UforKey:NSFilePosixPermissions];
        [
    fileManager setAttributes:attr ofItemAtPath:path error:nil];
        
    NSLog(@"0777 %@"path);
    }

    @
    end
     
  2. macrumors 603

    Joined:
    Aug 9, 2009
    #2
    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.
     
  3. cea
    thread starter macrumors newbie

    Joined:
    Oct 26, 2009
    #3
    ohh the comment belongs to another test code which was here before. i just forgot to remove it.
    Thank you for your info!
     

Share This Page