Is there a way to expose a directory, containing static libraries files or document other than specifying every one if the files? Example, for a software repo that has this structure:
+---- myProgram # expose as /usr/bin/myProgram using snapcraft command
+---- vendors/ # expose as /libs/myProgramLib for its descendants
| +---- data.txt
+---- companyB # automatically exposed as /libs/myProgramLib/companyB
| +---- data.txt # exposed as /libs/myProgramLib/companyB/data
I’m aware one way is to “tar” the
vendors folder and have a single command to “untar” it to the
/libs/myProgramLib, however, I have a feeling that this is a hackish way of doing things. Those files are static non-executable files mainly for read.
The reason for exposing a single folder is mainly to isolate each companies from mangling with the
snapcraft.yaml each time anyone of them adds a data file, which has the tendency to disrupt the build process.
Snapcraft doesn’t allow exposing a folder as a command. It will return the following error in particular:
IsADirectoryError: [Errno 21] Is a directory: '[targeted_command]'
Once those files are in the snap you reference them with
$SNAP as a prefix:
$SNAP/path/inside/snap. Getting those files into the snap is part of your build process, so you could for example use the
dump plugin to copy the files verbatim.
Thanks for the guide! I’ll run a test using the dump plugin. Quick question, from user standpoint, will they see the data file, say companyB as
based on the example?
If your build process puts the files in
libs/myProgramLib then that’s where you reference them from. If your build process puts the files elsewhere then you reference them in that location instead.
I managed to implement
$SNAP environment variable within the command application and implemented the
dump plugin. Pretty cool one. Basically, the
myProgram can read the contents insides its own snap using
What about exposing the
vendors folder like a command? I want to let user access and read the data files inside those sub-directories, without specifically create command pointing to each
Or am I missing something?
Do you mean access the files from outside the snap, or do you mean access the files from a different snap?
For accessing from outside, the files are all viewable (but not writable!) at
To access the files from another snap you can use the
content interface by defining a slot which tells snapd which directory to expose:
vendors-slot: # this is arbitrary
content: vendors # this is the name a plug connects to
- $SNAP/vendors # this is the folder you want to provide read access to
Note that files in
$SNAP are readonly due to snap filesystems being immutable because they use squashfs as the backing file format.
Outside the snap for user, apart from poking into the snap body like the one you mentioned. E.g. User can do:
$ cat /libs/myProgramLib/companyB/data.txt # for $SNAP/vendors/companyB/data.txt
Read access is sufficient. Is this type of export possible?