Comment 0 for bug 1660342

Revision history for this message
Naël (nathanael-naeri) wrote :

[XDG Special User Directories]

The XDG Special User Directories are a set of (eight) localized user directories for storing documents, downloads, music, pictures, videos, and so on. Their paths are defined for each user in the file $XDG_CONFIG_HOME/user-dirs.dirs, where XDG_CONFIG_HOME defaults to $HOME/.config.

Applications can read this file to find the directories in a locale-independent manner. Déjà-Dup uses the function GLib.Environment.get_user_special_dir to do so, in deja-dup/libdeja/DirHandling.vala. For instance, on a French locale and with default XDG Special User Directories, GLib.Environment.get_user_special_dir(UserDirectory.MUSIC) returns the path to the directory "Musique" in the user's home directory.

The file $XDG_CONFIG_HOME/user-dirs.dirs and the names of the XDG Special User Directories are updated by xdg-user-dirs-update according to the user's locale at the start of each user session. If the file or the directories don't exist, xdg-user-dirs-update creates them, based on the user's locale and the system default values in /etc/xdg/user-dirs.defaults.

[The test shell doesn't setup the XDG Special User Directories]

The test shell changes XDG_CONFIG_HOME to /tmp/dd-<temp>/config, but does not retrieve user-dirs.dirs in the process, or points to it, or recreates it with xdg-user-dirs-update.

As a result the new $XDG_CONFIG_HOME/user-dirs.dirs points to a non-existent file, and applications started in the test environment cannot find the user's special directories. The function GLib.Environment.get_user_special_dir returns "null" every time it is called, save for the desktop directory, because it falls back to "$HOME/Desktop" for compatibility with existing practise.

[Impact]

This is why the exclude list displayed in deja-dup-preferences (started from the test shell) does not feature the $DOWNLOAD directory that features in the default exclude-list key of the schema org.gnome.DejaDup: ['$DOWNLOAD', '$TRASH'].

This is why including $DOCUMENTS, $DOWNLOAD, $MUSIC, $PICTURES, $VIDEOS, $TEMPLATES and/or $PUBLIC_SHARE in the include-list and exclude-list keys of org.gnome.DejaDup does not lead to them being passed to duplicity as --include and --exclude options. That puzzled me to no end when I was testing a hack to solve bug 1549776, see comments 8, 11, 12.

From what I understand, $DOWNLOAD also features as an exclude in a number of test scripts (in deja-dup/libdeja/tests/scripts) which are run by the test shell during make check. It would be reduced to "null" there too.

[Fix]

Simply adding one of the following lines to the test shell's script, in the section "Create fake home environment", ensures that the user's current XDG Special User Directories are found, by creating a file user-dirs.dirs in the new XDG_CONFIG_HOME:

  ln -s "${HOME}/.config/user-dirs.dirs" "${XDG_CONFIG_HOME}/user-dirs.dirs"
  cp "${HOME}/.config/user-dirs.dirs" "${XDG_CONFIG_HOME}/user-dirs.dirs"
  xdg-user-dirs-update

Alternatively, new XDG Special User Directories can be created in the test environment /tmp/dd-<temp>, instead of using the user's current ones, which are not adapted to tests since they contain the user's data rather than unimportant test data. The simplest way to do so is to point HOME to the test environment as I suggest in bug 1660174, and then issue xdg-user-dirs-update:

  HOME="${ROOTDIR}"
  xdg-user-dirs-update

[Patch]

Attached is a patch for deja-dup/libdeja/DirHandling.vala that just adds printfs to the function parse_keywords in order to print the values of the XDG directories in the log file ("DEJA_DUP_DEBUG=1 deja-dup --backup > dd.log").

[References]

https://wiki.archlinux.org/index.php/XDG_user_directories
https://www.freedesktop.org/wiki/Software/xdg-user-dirs
https://valadoc.org/glib-2.0/GLib.Environment.get_user_special_dir.html
xdg-user-dirs-update(1)
xdg-user-dir(1)
user-dirs.dirs(5)
user-dirs.default(5)