Mac OSX 中数据库文件的最佳位置
我正在为一个已移植到 OSX 的应用程序开发一个安装程序,但我对此操作系统没有太多经验,因此我想知道安装我的应用程序将使用的数据库文件的最合适位置在哪里应用程序。
数据库文件相对较小,将由守护进程更新,但系统上的所有用户必须可以通过命令行工具访问。在 Linux 上我使用了 /var/lib/myapp/mydata.db,OSX 上的等效项是什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
OS X 上有两种方法:
OS X 定义应用程序和用户级“应用程序支持”文件夹。这些文件位于
/Library/Application Support
中(用于系统范围),位于~/Library/Application Support/
中用于用户级支持文件。应用程序支持文件夹应该由应用程序的包标识符(例如 com.company.app)命名,但许多只使用应用程序名称。一般来说,OS X 使用这种模式(系统级在/Library
中,用户级在~/Library
中用于应用程序支持、首选项、插件等)。/Library
默认情况下对于非管理员用户是只读的。如果您的命令行工具以root身份运行(或通过sudo
),那么您可以将数据库文件放在/Library/Application Support/your-app
中。当然,由于您需要在安装程序脚本(传统的 unix 样式或通过 OS X 安装包)中执行此操作,因此您可以修改 db 文件的读写权限。正如其他人所指出的,OS X 是 UNIX 操作系统,因此您可以根据自己的喜好创建
/var/lib
或任何其他文件夹。许多 UNIX 移植都这样做,因为这样可以使其与它们支持的其他操作系统更加一致。如果您这样做,请确保提供一个卸载程序脚本来删除您添加的文件夹(假设其他应用程序/用户/等没有向其中添加任何其他内容!)。 Mac 用户通常对安装程序在文件系统中乱扔垃圾而没有简单的方法来清理它感到不满。此外,MacPorts 和 Fink(OS X 的两个 OSS 包管理器)分别使用/opt
和/sw
树。您可能不想弄乱这些树,因为这可能会给这些包管理器的用户带来问题。当然,如果您想保持 UNIX-y 的特性,最好的方法之一就是为 MacPorts 或 Fink 打包您的应用程序。 MacPorts 属于 BSD ports 树谱系,Fink 属于 debian 谱系。 MacPorts 是 Apple 认可的包管理器,但两者似乎都很流行。There are two approaches on OS X:
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 viasudo
), 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.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.Macintosh HD/Library/Application Support/Your App/data.db 可能就是这个地方。
Macintosh HD/Library/Application Support/Your App/data.db would probably be the place.