[SOLVED] Writable file placed near to executable

Hi,
I have some ugly writen app that place file.lock near main executable and it should have RW access.
I put binary to /opt/myapp/mybinary inside my snap, so file /opt/myapp/file.lock need to be RW.
Is it possible to do something like this with snapcraft.yaml ?

Thanks!

You could use layouts to map /opt/myapp/file.lock to $SNAP_COMMON/… which will be writable, see https://snapcraft.io/docs/snap-layouts

upd, this fix permissions :

    override-build: |
      echo '#!/bin/sh
      chmod o+rw $SNAP_COMMON/file.lock
      ' >> hook
      chmod +x hook
      
    organize:
      hook: snap/hooks/install

Thanks for replay, but it is not the solution - $SNAP_COMMON is not writable without running applicaton with sudo (the same for $SNAP_DATA) - “Permission denied” Unfortunatly there is no way to use TMP dir as a source :frowning:

Run install app

snapcraft && sudo snap install --devmode test_0.1_amd64.snap && /snap/bin/test.app

snapcaft.yaml

name: test
base: core18
version: '0.1'
grade: devel
confinement: strict 
description: none
summary: none

apps:
  app:
    command: $SNAP/opt/myapp/run.sh

layout:
    /opt/myapp/file.lock:
      bind-file: $SNAP_COMMON/file.lock

parts:
  launcher:
    plugin: dump
    source: source
    override-build: |
      echo '#!/bin/sh

      echo "" >> /opt/myapp/file.lock
      
      echo "end"' >> run.sh
      chmod +x run.sh
            
      snapcraftctl build

    organize:
      run.sh: /opt/myapp/run.sh

How would people normally run this application when snaps are not used? Wouldn’t the same be true if the app was installed to any system wide read-only location?

The application is writen by left-handed developers from https://www.akmf.pl/ and ‘file.lock’ is just one of numerous problems of this app.

Instead of $SNAP_COMMON, which as you say is root owned, you could use $SNAP_USER_COMMON which is user owned for the user that is running

no I can’t use SNAP_USER_COMMON
stderr:
error: cannot pack “/root/prime”: cannot validate snap “test”: layout “/opt/myapp/file.lock” uses invalid bind mount source “$SNAP_USER_COMMON/myapp.lock”: reference to unknown variable “$SNAP_USER_COMMON”

ah right $SNAP_USER_COMMON isn’t usable for layouts

1 Like