I have some config files that need to be copied over to the host machine as they can be modified either by the user or new files added to the copied directories as the snap runs. Is there any way to copy files from a snap package when the install hook is running during the snap install process?
Yeah definitely, although I’m not sure what more I can tell you if you already know this fits within the install hook. Perhaps this blog post is helpful?
I did find that particular post a while back and it did shed some light on how to use install hooks. However when I tried to copy files from $SNAP/usr/bin I got a ‘directory not found’ error. Would you happen to know if the snap filesystem is mounted at the point of when the install hook is run?
Your hook is a program stored within the snap package, so by definition the snap would need to be mounted to run it.
Is it possible that the destination you’re trying to copy to doesn’t exist?
Yeah, @jamesh is right. Any chance you can minimally reproduce what’s not working so we can take a look and help you out?
note that hooks can only write files to places the snap itself can write to. i read your initial post as “i want to copy a file from the snap to the host filesystem”, this is only possible within the boundaries of the snap confinement, if you wanted to copy a file from $SNAP/usr/bin to /usr/bin, i do not think that there is an interface to do this.
Yeah, that was the case in the end. The file path I typed in had some invalid characters. You were all right about the install hook being able to access paths the snap could. Thank you very much for the help!