Hello,
I am creating a Python app that has XML configuration file. The app will write and update the configuration file when running. I would also like the file to persist after an update. After reading about Layouts I thought I would use $SNAP_DATA as it persists when refreshed.
My snapcraft.yaml had the following:
layout:
/etc/config.xml
bind-file: $SNAP_DATA/etc/config.xml
But when my app wrote to the config.xml file I would get permission error as it is owned by root. So I thinking maybe I should use $SNAP_DATA with the home directory but I am not sure of the layout syntax as I would not know the USER name in home folder? Any help would be greatly appreciated.
Environment variables
$SNAP_DATA
is equivalent to /etc
. In both cases non-privileged users cannot write.
$SNAP_USER_DATA
is equivalent to the user’s home directory and can be read/written by the user. This directory is backed up and restored across snap refresh
and snap revert
operations.
SNAP_USER_COMMON
is similar but will persist across snap refresh
and snap revert
operations.
Thanks for the reply.
Unfortunately when I try to use $SNAP_USER_COMMON I get the error:
error: cannot read snap file: layout “$SNAP_USER_COMMON/config.xml” uses invalid mount point:
reference to unknown variable “$SNAP_USER_COMMON”
The syntax I used is:
layout:
$SNAP_USER_COMMON/config.xml
bind-file: $SNAP_USER_COMMON/config.xml
I must be declaring the layout incorrectly?
Layouts are global, not user-specific. So you cannot use the $SNAP_USER_*
locations for them.
Thanks for the help.
So, I guess I shouldn’t use layouts for writable config files. What do you suggest is the procedure for declaring a writable config file in my snap?
If you are in control of the code of the app you’re snapping then make it write to $SNAP_USER_DATA
or $SNAP_USER_COMMON
. At a pinch you could use $HOME
because that is also defaulted to pointing to the same location as $SNAP_USER_DATA
.