hugolabe/Wike

state files like "historic.json" are saved directly into ~/.local/share instead of a subdirectory

Opened this issue · 2 comments

  • observed behavior: after running Wike, a bunch of files are saved directly under ~/.local/share.
  • expected behavior: Wike should organize its files under a subdirectory like ~/.local/share/wike so that users can more easily manage their application data.

repro:

  1. ls ~/.local/share
cozy/ dino/ flare/
  1. run wike, and then close it once the UI loads.
  2. ls ~/.local/share
booklists.json bookmarks.json cookies cozy/ dino/ flare/ historic.json languages.json

observe: several new files (booklists.json, bookmarks.json, ...) appear under ~/.local/share and aren't clearly associated with any particular app, whereas other applications (cozy, dino, flare) place their files under a subdirectory so that it's clear which files belong to which apps.

runtime info

  • wike 2.1.0 (built from source, not from flathub)
  • NixOS master (8cccce637e)
  • relevant environment:
$ env | grep XDG
XDG_CONFIG_DIRS=/etc/xdg:/home/colin/.nix-profile/etc/xdg:/nix/profile/etc/xdg:/home/colin/.local/state/nix/profile/etc/xdg:/etc/profiles/per-user/colin/etc/xdg:/nix/var/nix/profiles/default/etc/xdg:/run/current-system/sw/etc/xdg
XDG_CURRENT_DESKTOP=sway
XDG_DATA_DIRS=/nix/store/cxg4lgqs9wxbkh721jxzp5m9smc8vibf-desktops/share:/home/colin/.nix-profile/share:/nix/profile/share:/home/colin/.local/state/nix/profile/share:/etc/profiles/per-user/colin/share:/nix/var/nix/profiles/default/share:/run/current-system/sw/share
XDG_DESKTOP_PORTAL_DIR=/nix/store/kf1cgxscgm80d838hw3c929l33bqsmy6-xdg-portals/share/xdg-desktop-portal/portals
XDG_RUNTIME_DIR=/run/user/1000
XDG_SESSION_TYPE=wayland

Wike calculates its data paths in src/data.py:

_data_path = GLib.get_user_data_dir()

class Languages:

  items = {}
  global _data_path
  _file_path = _data_path + '/languages.json'

  ...

the docs for g_get_user_data_dir say

On UNIX platforms this is determined using the mechanisms described in the XDG Base Directory Specification. In this case the directory retrieved will be XDG_DATA_HOME.

the spec in turn says:

$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. "

it seems the desired behavior could be achieved with something like this (untested):

- _data_path = GLib.get_user_data_dir()
+ _data_path = os.path.join(GLib.get_user_data_dir(), "wike")

though that doesn't cover data migration for existing installs.

Thank you @uninsane

In flatpak this is not a problem since a data folder is created for each application. However, I suppose it would be better to fix it, but I have to make sure that user data is not lost when updating to the new version.