waycrate / swhkd

Sxhkd clone for Wayland (works on TTY and X11 too)
https://git.sr.ht/~shinyzenith/swhkd
BSD 2-Clause "Simplified" License
676 stars 47 forks source link

Default `swhks` log path creates literal `~` directory #157

Closed ajanon closed 2 years ago

ajanon commented 2 years ago

Version Information:

Describe the bug: When XDG_DATA_HOME is not set, swhks creates a directory named with a literal ~ to store its logs.

Expected behavior: swhks should translate ~ to the actual HOME directory path of the user.

Actual behavior: When XDG_DATA_HOME is not set, swhks writes to the default location ~/.local/share/swhks/swhks-{}.log. This unfortunately does not write in the home directory (~ translated to an actual path) but creates an actual directory with the name being a literal ~ at the location where swhks was started.

To Reproduce: Start swhks with XDG_DATA_HOME not set (unset -v XDG_DATA_HOME). On the first log line written by swhks, the ~ directory will be created at the starting location.

Additional information: The issue stems from (at L67): https://github.com/waycrate/swhkd/blob/2832de8cc2ef9d28aa7ee57954a1a05029e7aca8/swhks/src/main.rs#L54-L69

If we follow the XDG Base Directory Specification, XDG_DATA_HOME should indeed default to $HOME/.local/share, with $HOME referencing the environment variable of the same name. ~ should probably be changed to reference the HOME environment variable.

The HOME environment variable seems safe to reference as it is specified in POSIX and set by the system. If HOME is not set, I think it is okay to bail out as the user probably has a peculiar configuration (and as such, should be able to set XDG_DATA_HOME as needed).

Shinyzenith commented 2 years ago

Nice catch! Thanks for the details and meticulous bug report, much love! ❤️