Permissions for a utility snap to read/write user files

Hi, a newbie question. I have a small C++ math utility that reads user .txt or .csv files as input and outputs results also in form of text files. With “strict” confinement it cannot read the input (unless this input is in a specific place, snap’s own home directory). Is this better for me to switch to “classic” confinement or I would be better adding interfaces? If so, can anyone point out to a good example: I need to read user files (names are given by user in command line) and output result text file - with default name (which I can make always the same).

Thank you.

just add the home interface plug to your snap, that should give you full access to all non-hidden files in the users home dir

Thank you! I already sort of figured it out after a few hours of struggle. Another more important question if you can help: I have a C++ SDL2 application that uses a few fonts, images and sounds. SDL2 just reads those files, so they have to be on disk (ideally together with the app). And unlike it is in Windows you cannot simply bundle resources into an executable. The question is how do I make snap executable to also have access to these resources? I tried adding a separate part with snap/local, with dump plugin to include a font file, but this so far has not helped. I also read that there are $SNAP/data-dir… objects I can use but I cannot see any examples. It would be very helpful if you provide a few sample .yaml files for applications like mine that need to use raw resource files bundles in one package with executable. The only C++ example on your site is very limited, I have to spend hours digging any relevant info and watch hours of videos to solve a trivial task. Thank you.

The idea is to bundle the assets in the snap, and then let the executable load them at runtime from $SNAP/path/to/assets. The assets path is typically set using an environment variable, but if the executable can’t be patched or configured to look for resource files inside the snap directory you can use layouts to map them to a different location in the filesystem.

Thank you for clarifying this. What I missed is to read a resource, I have to call getenv(“SNAP”) in my C++ code and use this as prefix to get the full path.

Yuriy.

1 Like

If you have control over that, maybe making the application read an environment variable that points to an alternative assets directory (something like MYAPP_DATA_DIR, defaulting to /usr/share/myapp) could be more flexible and allow it to run from a non-snap environment as well. Then when running from a snap the variable could be configured to point to $SNAP/usr/share/myapp.