Troubleshooting Access Issues with SNAP_USER_DATA and SNAP_COMMON in Snap Applications

I’m currently working with Snap applications on my Linux system, but I’m running into an issue where certain environment variables seem to not be set correctly. Specifically, I’m having trouble with SNAP_USER_DATA and SNAP_COMMON directories not being accessible by the application, which is causing my snap to fail when trying to store user data and configuration files.

I’ve tried checking the environment variables using the env command inside the snap, but the directories don’t seem to exist, even though I know they should. I’ve also checked the Snapcraft documentation on environment variables, including the check.snapcraft.io/docs/environment-variables#heading–snap-common, and tried troubleshooting the paths, but I still can’t resolve the issue.

Has anyone experienced something similar and found a solution? I’m unsure if the issue is related to the snap’s confinement or if it’s an issue with how the directories are mapped in the snap environment. Any guidance on how to solve this would be appreciated!

They are two completely different things, everyhting with $SNAP_USER_* lives in the users home, i.e. $SNAP_USER_DATA corresponds to ~/snap/<snapname>/current and $SNAP_USER_COMMON points to ~/snap/<snapname>/common … both of these directories get created at install time of a snap

If you are packaging things like system services and daemons you will instead be using $SNAP_DATA and $SNAP_COMMON both are pointing to similar file structures as above but under /var/snap instead of ~/snap … since /var requires you to be root to be able to write to these dirs you do not want to use these vars for apps started as a normal user …