On 15 Jan 2009, at 10:31 am, Chunk 1978 wrote:

so an app doesn't need administrative rights to writeToFile in the / tmp folder?
_______________________________________________


Don't do that.

Instead use the FindFolder with the 'kTemporaryFolderType' constant. Here's a Cocoa wrapper (a category on NSFileManager) to help:

@implementation NSFileManager (FindFolder)


- (NSString*) pathToFolderOfType:(const OSType) folderType shouldCreateFolder:(BOOL) create
{
        OSErr           err;
        FSRef           ref;
        NSString*       path = nil;
        
        err = FSFindFolder( kUserDomain, folderType, create, &ref);
        
        if ( err == noErr )
        {
                // convert to CFURL and thence to path
                
CFURLRef url = CFURLCreateFromFSRef( kCFAllocatorSystemDefault, &ref ); path = (NSString*) CFURLCopyFileSystemPath( url, kCFURLPOSIXPathStyle );
                CFRelease( url );
        }
        
        return [path autorelease];
}


@end


But yes, once you have the path you should have write permission for it.

Note also though, that for the case of "safe saving" (i.e. write to a temporary file then swap with the 'real' file), you don't need to do that yourself. Just pass yes in the 'atomically' parameter in methods such as [NSData writeToFile:atomically:];

hth,

Graham


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to