I am building command line application, and I have a need to save some temp data to files. I do not know where is convention for applications to store their cache on unix based systems (in this case Ubuntu 12.0.4)?
|
"Unix based systems" is far too general a category to make any kind of generally-applicable determination that will apply to all Unix based systems. The problem is that the filesystem structure (and the "proper" / "conventional" place to put things) is so wildly different between different flavors of "Unix" (if you can even call it that) that you pretty much have to handle it on a case-by-case basis. A few examples:
The answer is that the canonical, socially acceptable, well-integrated convention for where to store anything on any operating system, whether it's a distro of Linux, BSD, Solaris, HP-UX, etc. is dependent on the exact circumstances. Specifically:
There is no straight answer for this without considering all the factors. However, for Ubuntu 12.04 specifically, if you are building your package into a Furthermore, if there are no advantages to saving the cache data across boots of the system, I think it could also belong in /tmp. Note that you are going to run into these pathing convention problems for every type of file that your program uses: shared data, executable files, libraries, help files, images, sound, web pages, and on and on. So I have to wonder, if you are asking about cache files, how you are planning to handle the other file types. Are you just making naive assumptions and hoping that no one disagrees with you? If you haven't read any Ubuntu docs or standards suggesting where to put them, it is a bad idea to just assume one thing or another. For example, always sticking libraries in /usr/lib could be a mistake, as depending on the situation they may belong elsewhere. Additionally, as a software developer, I think the most responsible thing to do is allow the end-user to decide where to put their files. You can set defaults, but users (and distributors) can and will customize the build to fit with their distro. The easiest way to do this is to build your program using GNU Autoconf. Autoconf is a build system where the user can pass command-line arguments to the build script to change the paths of the various "directory types" away from the defaults. Almost every distribution has a build script for every Autoconf package that sets the distro-appropriate conventional directories for each type. They even specifically have a directory type for cache: sharedstatedir. |
|||||
|