Help understanding the content interface

I’ve been trying to make a PoC of the content interface https://github.com/joedborg/snap-content-interface-test

Very basically, I’m trying to get a file snapped in the provider (hippo-food) to appear in the consumer (hungry-hippo). In this instance, it’s food.

I can see the food file is in the hippo-food snap:

➜ ll -h /snap/hippo-food/current/
total 1.0M
-rw-rw-r-- 1 root root 1.0M Jun  9 15:00 food

But, when I connect the interface

snap connect hungry-hippo:mouth hippo-food:food

…the file does not seem to end up in $SNAP_COMMON, as specified here https://github.com/joedborg/snap-content-interface-test/blob/master/consumer/snap/snapcraft.yaml#L14

➜ ll -h /var/snap/hungry-hippo/common
total 0

Have I misunderstood how this is meant to work? On top of this, I’d like to know if I can specify a hook to act upon the file, in the consuming snap, when the connection is made.

Many thanks,
Joe

The content interface is only effective for the snap itself, i.e. you need to be in the snap’s mount namespace. So if you did

snap run --shell hungry-hippo -c 'ls -h $SNAP_COMMON'

I think you would see the food.

Ah thanks Ian! That’s working, however on the first attempt, I got this warning before it listed:

update.go:85: cannot change mount namespace according to change mount (/snap/hippo-food/x1/food /var/snap/hungry-hippo/common/food/food none bind,ro 0 0): cannot use "/snap/hippo-food/x1/food" as bind-mount source: not a directory

Should I log that?

Can you show the snapcraft.yaml before you file a bug? It looks like you might have a layout error, perhaps using bind instead of bind-file?

Sure,
Consumer https://github.com/joedborg/snap-content-interface-test/blob/master/consumer/snap/snapcraft.yaml
Provider https://github.com/joedborg/snap-content-interface-test/blob/master/provider/snap/snapcraft.yaml