Opened 12 years ago

Closed 8 years ago

Last modified 5 years ago

#6036 closed defect

POSIX: Use XDG dirs instead of HOME

Reported by: SF/mccannwj Owned by: lordhoto
Priority: high Component: Port: Linux
Version: Keywords:
Cc: Game:

Description

We store information in ~/.scummvm. It would be better to use the locations defined in the XDG Base Directory Specification.

https://live.gnome.org/GnomeGoals/XDGConfigFolders http://standards.freedesktop.org/basedir-spec/latest/

Ticket imported from: #3527150. Ticket imported from: bugs/6036.

Change History (19)

comment:1 by sev-, 12 years ago

Well, ~/.* is the Right Thing(TM), Unix style, and 99.95% of programs use that. Gnome works mainly on *nix clones. I see no point of moving it anywhere.

What are the advantages specific to our project? None of the things mentioned in the list you point to are applicable to ScummVM. E.g. it is safe to kill this file anytime, it is universal, backing it up = copy single file, data file paths are specified via GUI and are not enforced by the program, etc.

comment:2 by SF/mccannwj, 12 years ago

Storing in $HOME is no longer the Right Thing(TM) on any unix style machine. This has nothing to do with GNOME. In fact this standard supports not only unix style systems but also mac and windows in most implementations. The GLib apis are particularly good in this respect.

The advantages are for the user and admin, mostly. Not necessarily your project. Just being considerate to your users and a good citizen of the ecosystem I suppose. I don't think it really involves any cost. I can provide a patch myself soon I hope.

comment:3 by sev-, 12 years ago

Does it mean that reading XDG_CONFIG_HOME environment variables is enough?

Looking into glib sources, I see that if this variable is not set, it uses ~/.config, however the specifications mention /etc/xdg directory. So there is an inconsistency.

Also this variable is not set neither on my Ubuntu 12.04 (with Unity), nor on Mac OS 10.7.4.

Adding dependency on glib for the sake of retrieving this value looks like an overkill for me.

So, any suggestions or hints?

comment:4 by SF/mccannwj, 12 years ago

XDG_CONFIG_HOME and XDG_CONFIG_DIRS are different. The first is per-user and typically in the home directory. The second is systemy typically.

The variable isn't normally set because the default is usually correct. However, a system admin or vendor can set it to whatever they wish. This is sometimes done when multiple operating systems need to be supported using a shared home directory.

So, from a quick look it seems that dot files are used for a few things.

log files -> syslog or XDG_CACHE_HOME/scummvm saved games -> XDG_DATA_HOME/scummvm/ configuration -> XDG_CONFIG_HOME/scummvm

One nice thing about glib (there are lots of nice things about glib) is that it takes care of windows support for you. But if you don't want to add a dependency on it you can just do the same things that it does. g_get_user_cache_dir() for example.

Hope that helps.

comment:5 by tsoliman, 12 years ago

I did some digging to find this out since some other games are putting their saves in ~/Documents/

http://freedesktop.org/wiki/Software/xdg-user-dirs

Basically shell scripts are supposed to check for and source ~/.config/user-dirs.dirs (they should look for $XDG_CONFIG_HOME and fall back to ~/.config) Then they'll get the environment variables. Stuff that runs at logs uses /etc/xdg to populate that file.

(~/.config is the default for XDG_CONFIG_HOME)

Implementing this shouldn't be too hard and ScummVM could probably fall back to the old behavior if anything goes wrong.

Migration is a different story.

comment:6 by SF/mccannwj, 12 years ago

Just curious, what games? Using Documents sounds wrong to me. I think using USER_DATA_HOME is better.

comment:7 by tsoliman, 12 years ago

botanicula is the game but that's besides the point. The environment variables for xdg in debian sid are the following:

XDG_DESKTOP_DIR="$HOME/Desktop" XDG_DOWNLOAD_DIR="$HOME/" XDG_TEMPLATES_DIR="$HOME/" XDG_PUBLICSHARE_DIR="$HOME/" XDG_DOCUMENTS_DIR="$HOME/Documents" XDG_MUSIC_DIR="$HOME/Music" XDG_PICTURES_DIR="$HOME/Pictures" XDG_VIDEOS_DIR="$HOME/

There is no USER_DATA_HOME that I can see

comment:8 by SF/mccannwj, 12 years ago

Ok, I'll try to follow up with that game and file a bug. Thanks for that info.

From http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables "$XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored. If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used. "

comment:9 by lordhoto, 12 years ago

I agree that adding glib as dependancy is really a bit much. Especially for using it on Windows, where it seemed a PITA to build it easily with MSVC. At least I had some troubles when I tired to do an x64 build. But that has been a while, so maybe it's better these days.

As I understand it the base-dir specification was made to declutter $HOME and give some standard paths for different types of files used by programs on desktop machines. Then again the whole specification fails to point out any benefits, so maybe the intention here was something completly different... So I am not really sure I can say I like it too much. It would really be better when it would at least point to other documents which points out why using $HOME etc. is bad for example.

It might make sense to adpot that standard never the less, looking at my $HOME/.local/share and $HOME/.config more and more programs seem to adopt it. The proposed places to put the config file, saved games seem fine to me. I am not sure whether I feel that "XDG_CACHE_HOME" sounds really a place to put a log, but I guess from the specification it seems the place which fits best.

Anyway we need to make sure people with config files etc. in the old locations don't need to manually migrate to the new locations IMHO. That might need some small effort.

comment:10 by sev-, 12 years ago

This bug is nice to get fixed before the release. Raising priority for keeping the track.

comment:11 by sev-, 12 years ago

Priority: normalhigh

comment:12 by SF/eheintzmann, 11 years ago

What is planned now about FreeDesktop XDG basedir specification for ScummVM?

http://ploum.net/post/207-modify-your-application-to-use-xdg-folders https://live.gnome.org/GnomeGoals/XDGConfigFolders http://standards.freedesktop.org/basedir-spec/latest/

comment:13 by lordhoto, 11 years ago

As it seems, there's currently nobody working on that.

comment:14 by SF/eheintzmann, 11 years ago

According to XDG Base directory specification: User data should go into $XDG_DATA_HOME (which default to ~/.local/share), user preferences should go into $XDG_CONFIG_HOME (which default to ~/.config) and cached data should go to $XDG_CACHE_HOME (which default to ~/.cache). More details at : http://ploum.net/post/207-modify-your-application-to-use-xdg-folders https://live.gnome.org/GnomeGoals/XDGConfigFolders

Full specification can be found at: http://standards.freedesktop.org/basedir-spec/latest/

The Freedesktop.org XDG base directory specification have good de facto adoption. It has been adopted by: - GNOME ( https://live.gnome.org/GnomeGoals/XDGConfigFolders ) - GTK+ ( https://bugzilla.gnome.org/show_bug.cgi?id=646631 ) - KDE ( http://techbase.kde.org/KDE_System_Administration/XDG_Filesystem_Hierarchy#Freedesktop.org_and_Standard_Directories ) - QT ( http://harmattan-dev.nokia.com/docs/library/html/qt4/qsettings.html#setPath ) - XFCE ( http://docs.xfce.org/xfce/xfce4-session/advanced in Files and Environment Variables ) - LXDE - Razor-qt - VLC ( https://trac.videolan.org/vlc/ticket/1267 ) - GStreamer ( https://bugzilla.gnome.org/show_bug.cgi?id=518597 ) - Chrome ( http://code.google.com/p/chromium/issues/detail?id=16976 ) - many more upstream applications - Ubuntu ( http://brainstorm.ubuntu.com/idea/6557/ & http://packages.ubuntu.com/fr/source/precise/libxdg-basedir ) - Debian ( http://packages.debian.org/squeeze/libxdg-basedir1 ) - Red Hat - Fedora - Suse - many more distributions

I think that ScummVM should use same locations than the vast majority of Desktop environment and applications.

There are real advantages of following this specification : - a lot less cluttered $HOME - Make backups a lot more safer and easier. Backuping your $XDG_DATA_HOME along with your files is enough (or just excluding $XDG_CACHE_HOME) - A lot easier to reset a default configuration if you want/need it (and without any risk to loose informations). Even for the software itself could choose to reset $XDG_CONFIG_HOME if needed. - Avoid some strange bugs that happens because you had a old version of some configuration file - A lot more of flexibility and portability because no path are hardcoded.

comment:15 by lordhoto, 8 years ago

Summary: use XDG dirs instead of HOMEPOSIX: Use XDG dirs instead of HOME

comment:16 by lordhoto, 8 years ago

Appareantly nobody else bothered to work on this. I opened a pull request now which switches to this style, but still uses the old one if that has been around before: https://github.com/scummvm/scummvm/pull/656

comment:17 by lordhoto, 8 years ago

Owner: set to lordhoto
Status: newclosed

comment:18 by lordhoto, 8 years ago

Merged the PR so this is finally implemented.

Users will need to migrate to new paths themselves for the time being. We still use the old locations if they are present.

comment:19 by digitall, 5 years ago

Component: Port: Linux
Note: See TracTickets for help on using tickets.