# Best place to put external files?



## Eponasoft (Oct 8, 2009)

OK so I've been working on some applications for FreeBSD, but they use plenty of external files (content, configuration, etc). One of them is a game, the other is a desktop utility. In "Windows world", I would simply put such files in subdirectories where the binary is. However, I noticed that when you start a program from Konqueror, this doesn't tend to work since the path returned is the home directory of the user rather than the path of the binary you are running. Obviously it works fine from the console, but not all users use the console. So what I did to work around this was to select a base directory that is pretty much guaranteed to exist on all FreeBSD systems, which would be /usr/local/share. So what I ended up with is /usr/local/share/eponasoft/appname/subdirs*/data*. Is this considered proper form, or is there a better, more standardized way of doing things? For the game, I could probably consider putting the files at ~/.whatever, but that won't work for the desktop utility since it needs to be accessible to anyone on the system. The desktop utility keeps user profile information in a subdir off of the user's home dir, but it also has content that can be downloaded that is accessible to every user who uses it.

Also, since these are to be cross-platform applications, does anyone have a recommendation for how this could be done on a Linux machine? For a Windows machine, I already have the process ironed out, so that's not a problem, but I'm unfamiliar with the standard Linux filesystem hierarchy...if such a thing exists.


----------



## aragon (Oct 8, 2009)

It depends what you are storing.

Configuration files:
/usr/local/etc

Documentation:
/usr/local/share/doc/<projectname>

Libraries:
/usr/local/lib

Headers:
/usr/local/include

Generic data:
/usr/local/share/<projectname>

Binaries:
/usr/local/bin and /usr/local/sbin

Binary plugins:
/usr/local/libexec

Man pages:
/usr/local/man

Info pages:
/usr/local/info


If you don't want to split things up by type, I believe the accepted practice is:
/usr/local/<projectname>

I guess /usr/local/eponasoft would be acceptable.


----------



## Eponasoft (Oct 8, 2009)

Well, it's that I noticed several other applications dumping stuff into /usr/local/share so I figured it was the right place. For example, there are almost 30 gnome directories there on my system and I don't even use gnome...


----------



## aragon (Oct 8, 2009)

Yea, apps store generic data there, such as images, sound files, skins, etc.


----------



## vivek (Oct 8, 2009)

User specific config should go in ~/.appname/ directory. For example, my vim config will go in ~/.vimrc file.


----------



## SirDice (Oct 8, 2009)

Have a look at hier(7) it explains what the purpose of all the directories are.


----------



## Eponasoft (Oct 8, 2009)

OK so it looks like I was right for using /usr/local/share and ~/.app. Thanks everyone.  I tried downloading and installing a minimalist Linux (called aLinux) to see if it set up the hierarchy the same way but it refused to install...it just kinda hung while installing (a common problem with the typical hack Linux, it seems).


----------



## phoenix (Oct 8, 2009)

"Linux" uses a very different directory layout.  It's "documented" in the Filesystem Hierarchy Standard (FHS).  However, each distro uses a modified, custom version of the FHS (which is why I consider it "documented").

The big differences from FreeBSD are:

everything is installed into /usr with configs for everything under /etc (no separation of OS from apps)
/usr/local is only for stuff manually compiled by the sysadmin
/opt is for third-party binary installs


----------



## Eponasoft (Oct 8, 2009)

That's a pretty stupid layout.


----------



## DutchDaemon (Oct 8, 2009)

Wait 'til your website turns up under /srv/www/ ...


----------



## Eponasoft (Oct 10, 2009)

That would suck. 

Well, this project has been boatloads of fun. Plenty to learn about when it comes to doing directory strings...like don't try to fopen "~/.directory/file" or it will segfault.  getlogin_r() followed by getpwnam() worked, though I did see people suggesting getenv("HOME") though that can apparently be spoofed and I'd prefer not to have that happen. I'm so not used to dealing with variable paths...I've only ever done absolute paths in C. Ah well...forward march!


----------



## troberts (Oct 14, 2009)

vivek said:
			
		

> User specific config should go in ~/.appname/ directory. For example, my vim config will go in ~/.vimrc file.


Is the ~/.config directory a "legacy" way for storing configuration files?


----------



## aragon (Oct 15, 2009)

AFAIK, it is a new way for storing configuration files, and I personally prefer it.


----------



## lme@ (Oct 19, 2009)

AFAIK ~/.config is used by some Gnome / Gtk apps.


----------



## DutchDaemon (Oct 19, 2009)

Sounds about right.


```
~/.config]$ ls
Google		autostart	geeqie		orage		xfce4-session
Terminal	en.dic		gtk-2.0		ristretto
Thunar		en.exc		midori		vlc
Trolltech.conf	enchant		mousepad	xfce4
```


----------



## vivek (Oct 19, 2009)

Most gnome apps prefers ~/.gnome or ~/.gnome2 (2.x series)


----------



## tobe (Oct 20, 2009)

~/.config is a freedesktop.org specification:


> If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used.


http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html


----------

