• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: /tmp folder ok?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: /tmp folder ok?


  • Subject: Re: /tmp folder ok?
  • From: Graham Cox <email@hidden>
  • Date: Thu, 15 Jan 2009 10:44:30 +1100


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 (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: /tmp folder ok?
      • From: "Chris Parker" <email@hidden>
References: 
 >/tmp folder ok? (From: "Chunk 1978" <email@hidden>)

  • Prev by Date: Re: /tmp folder ok?
  • Next by Date: Re: Debugging objc_msg errors
  • Previous by thread: Re: /tmp folder ok?
  • Next by thread: Re: /tmp folder ok?
  • Index(es):
    • Date
    • Thread