views:

128

answers:

2

I'm working on an installer for an application that I have ported to OSX, but I don't have much experience with this OS so I want to know where is the most appropriate location to install a database file that will be used by my app.

The database file is relatively small, and will be updated by a daemon process but must be accessible to all users on the system via a command-line tool. On Linux I have used /var/lib/myapp/mydata.db, what would be the OSX equivalent?

+3  A: 

Macintosh HD/Library/Application Support/Your App/data.db would probably be the place.

Jarrod
/Library/Application Support/ is probably best if it's primarily a user-interactive app; if it's more like a piece of system infrastructure then /var/db/ might be more appropriate.
Gordon Davisson
Remember, this is UNIX, so the path does not necessarily start with "Macintosh HD". /Library/Application Support/... is what you mean.
Barry Wark
Actually, the path would _never_ start with "Macintosh HD" (you're probably thinking of Mac OS 9 or earlier); absolute paths on Unix and Mac OS X always begin with a /.
titaniumdecoy
Actually, it's a horrible path to use. Won't work at all. I didn't even escape the spaces. I was just showing him where the directory was, and making it clear not to use the user's library if he wants it to be available to all users.
Jarrod
+2  A: 

There are two approaches on OS X:

  1. OS X defines application and user-level "application support" folders. These are in /Library/Application Support for system-wide and in ~/Library/Application Support/ for user-level support files. Application support folders are supposed to be named by the app's bundle identifier (e.g. com.company.app), but many just use the application name. In general, OS X uses this pattern (system-level in /Library and user-level in ~/Library for application support, preferences, plugins, etc.). /Library is, by default read-only for non-administrator users. If your command line tool is run as root (or via sudo), then you could put your database file in /Library/Application Support/your-app. Of course, since you'll need to do this in an installer script (either traditional unix style or via an OS X installation package), you could modify the read-write permissions of your db file.

  2. As others have pointed out, OS X is a UNIX OS, so you can create /var/lib or any other folder to your liking. Many UNIX ports do this as it keeps things more consistent with other OSes that they support. If you do this, make sure to provide an unistaller script that removes the folders you add (assuming nothing else has been added to them by other apps/users/etc.!). Mac users generally frown on installers throwing crap all over the file system without an easy way to clean it up. Also, MacPorts, and Fink (two OSS package managers for OS X) use the /opt and /sw trees respectively. You probably don't want to mess with those trees as it could cause problems for users of these package managers. Of course, one of the best ways to go if you want to keep things UNIX-y is to package your app for MacPorts or Fink. MacPorts is of the BSD ports tree lineage and Fink is of the debian lineage. MacPorts is the Apple-sanctioned package manager, but both seem popular.

Barry Wark