How to deal when an app has a hard coded path

Hi there,

When an app has a hardcoded path (a check for existence in this case) in it to say /usr/lib, is there a way to deal with this in snapcraft? Or is there some work to be done upstream to make the application more portable? Or are you just using classic confinement at this point?

Thanks for the time.

If you can access the source code you could investigate to see whether the author has provided for relocation via checking of an environment variable or command line switch. Usually, if they have allowed for it, hard coded paths will each have a related environment variable or command line switch which will override the inbuilt path when it is set.

If environment overrides are allowed you just need to ensure your snap-specific paths are set in the environment via the environment: section of the yaml or via a launcher script which sets the environment and then chain-loads the final executable. For command-line switches you need to either amend the command: to include the switches or again use a launcher script which enforces the switches. In both cases there is a variable called $SNAP which contains the full path to your snap’s base directory, so your path for /usr would be overridden with $SNAP/usr.

Unfortunately right now there is no way of allowing the application to find it’s files in those hard coded paths without such a provision.

1 Like

@zyga-snapd isn’t this something the layouts could help with?

1 Like

We actually coded in a few checks to see if the app is running as a snap, or via the traditional means. Then set the paths as needed.