For the archives: Yes, the dirhelper daemon will delete data out from under NSTemporaryDirectory() on Leopard.
If your app creates files in NSTemporaryDirectory() and the user leaves the app running for more than 3 days (or unzips an archive containing files with a modification date more than three days in the past), the files will be deleted out from under the application. The NSTemporaryDirectory() semantics appear to have changed recently. As recently as the doc set in Xcode 3.1.2, the documentation for NSTemporaryDirectory() read: "Files put in the temporary directory may be moved to the Trash in a "Recovered Files" directory when the user's system is restarted. You should therefore ensure that you delete temporary files before your application terminates." ... which implies that the data will be available for the lifetime of the app. This notion is reinforced by the "Where to Put Application Files" article at http://developer.apple.com/DOCUMENTATION/MacOSX/Conceptual/BPFileSystem/Articles/WhereToPutFiles.html, which says: "Many applications use temporary files to store transient data. The life span of a temporary file varies depending on its intended use. The file may be used to store scratch data or calculations, such as when rendering a 3D image, and deleted immediately upon completion of those calculations. It may store runtime data about the application and be deleted only when the application terminates. It may also linger until the next time the user launches the application. For example, an application typically uses a temporary file to store an autosave version a document, which acts like an insurance policy against application or system crashes. Mac OS X provides an established set of directories for storing temporary files... Cocoa applications should use the NSTemporaryDirectory function in Foundation Kit." However, the documentation now on-line at http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Functions/Reference/reference.html reads: "The temporary directory is determined by confstr(3) passing the _CS_DARWIN_USER_TEMP_DIR flag. The erase rules are whatever match that directory." Though the erase rules aren't documented(!), the they are specified in /System/Library/LaunchDaemons/com.apple.bsd.dirhelper.plist: erase normal files that were last accessed more than three days ago. Note: You can verify that dirhelper is loaded using a trick described in Tech Note TN2083 (http://developer.apple.com/technotes/tn2005/tn2083.html). $ pid=`sudo killall -s kextd | cut -f 3 -d ' '` $ sudo launchctl bslist $pid | grep dirhelper Submitted as rdar://6511474 -Steve On Thu, Jan 15, 2009 at 10:41 AM, Steve Shepard <steves...@gmail.com> wrote: > Question: > > It appears that dirhelper can delete files from NSTemporaryDirectory() > while an app is running. Is this a bug in > com.apple.bsd.dirhelper.plist, which specifies that dirhelper run > periodically? > > Background: > > I'm trying to track down a bug that a few users have reported but that > I can't reproduce. Console logs from these users indicate that files > that should be in a subdirectory of NSTemporaryDirectory() have been > deleted. > > On Leopard, the command /usr/libexec/dirhelper is responsible for > cleaning out old files in /var/folders, which is a parent directory of > NSTemporaryDirectory(). > > According to /System/Library/LaunchDaemons/com.apple.bsd.dirhelper.plist, > dirhelper is run at launch and AT REGULAR INTERVALS AFTER THAT to > remove files that are more than 3 days old. > > <key>RunAtLoad</key> > <true/> > <key>StartCalendarInterval</key> > <dict> > <key>Hour</key> > <integer>3</integer> > <key>Minute</key> > <integer>35</integer> > </dict> > <key>EnvironmentVariables</key> > <dict> > <key>CLEAN_FILES_OLDER_THAN_DAYS</key> > <string>3</string> > </dict> > > (Note: You can find the dirhelper source at > http://www.opensource.apple.com/darwinsource/10.5.6/system_cmds-433.4/dirhelper.tproj/) > > If an app creates files in NSTemporaryDirectory() and the user leaves > the app running for more than 3 days (or unzips an archive containing > files with a modification date more than three days in the past), the > files will be deleted out from under the application ... won't they? > > -Steve > _______________________________________________ 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