Is there a canonical way for programs that use the “home” interface to refer to the actual home directory? Standard methods like Qt’s QDir::homePath() merely return $HOME which is always set to $SNAP_USER_DATA. Consequently, applications that plug into home in order to access the user’s files will typically initialize their file dialogs at $SNAP_USER_DATA, from which the user must awkwardly go up several levels in order to access their documents. Keepassxc does this for example. Users should not need to know the relation between $SNAP_USER_DATA and their home directory in order to access their files.
desktop-launch launcher provided by ubuntu/snapcraft-desktop-helpers project should link all XDG standard user directories (Documents, Music, Pictures…etc.) to the user’s real ones so the snapped application can easily access these files.
You definitely still have
$USER set in the environment so using
/home/$USER might work … there are other ways like using getpwnam() to get the pw_dir from /etc/passwd (that is likely not confined).
Since this question doesnt come up for the first time, i wonder if we should not have something like “$ORIG_HOME” or some such in the environment exported by snapd. That would make it easier to handle and also cover exotic locations for homedirs (
/var/home/$USER comes to mind) that would only live in the passwd file but not be known inside the snap environment. Filing a whishlist bug against snapd might make sense here …
Classic confinement for epitopepredict snap
I still face this issue now. I am not sure is there any recommended to solve this?
I am using Rust’s dirs::home_dir() function and it returns
/home/<user>/snap/<package> path instead of
/home/<user>. This is happening only when I install install via snap.
I did some digging and seems like
dirs::home_dir() function depends on $HOME.
As @Lin-Buo-Ren mentioned,
snapcraft-dektop-helpers handles the
Documents, Videos, etc directories.
What’s the recommended way do solve this issue?
Should I add additional conditions or use this method?