I’m trying to understand how the Layout is supposed to function. My ultimate goal is to make available a configuration file within $SNAP_DATA that a utility (one of two apps in my snapcraft.yaml) could then modify when called by a snap set command (from the outside world).
My currently configured Layouts work as expected for files and directories that I need to be in place in $SNAP_DATA during the snap build process; the main app launches and writes to them.
My Layout for the configuration file though, also works in that the bind-file results in the file being in the location specified by the Layout within $SNAP_DATA, but the file is empty (0 bytes).
I’ve read different posts about migrating a configuration file over from /etc, /home, $SNAP etc using an install-hook and/or configure-hook, but nothing has worked for me. What is the best practice to achieve this? A few posts explain away without the use of a Layout but I can’t tell if that’s only because the post preceded the intro of Layouts, or not. Thx in advance!
I was able to achieve my interim step of getting a writable copy of my conf.json file deposited into $SNAP_DATA by using an install-hook and not a Layout nor configure-hook.
Here’s the install-hook that worked for me.
#!/bin/sh -e
Copy conf.json file to $SNAP_DATA
validate the file’s existence
if [ ! -f $SNAP/conf/conf.json ] ; then
echo “ERROR: The file does NOT exist”
exit 1
fi
If it exists, copy conf.json from $SNAP to $SNAP_DATA
But I still have the question from my post → I had thought I could achieve this same result via bind-file Layout but it resulted in an empty file instead. For my own understanding, why would that happen?