Layout: bind-file does not reflect changes to source file

I’ve been trying to find the underlying cause of this, but have been unable to figure it out beyond the following:

Using this layout:

layout:
  /etc/ld.so.cache:
    bind-file: $SNAP_DATA/etc/ld.so.cache

When the snap is refreshed and a new $SNAP_DATA/etc/ld.so.cache generated from the available libraries in the snap, by a post-refresh hook, the file found at /etc/ld.so.cache does not reflect the changes. The $SNAP_DATA file is successfully updated, but the mirror at /etc has the original file’s timestamp and content.

When you update the $SNAP_DATA/etc/ld.so.cache file content are you unlink’ing or removing the file first? If so, I don’t think you want to do that, as per @zyga’s explanation here, I think you instead probably want to totally overwrite that file rather than remove it or rename some other file to that $SNAP_DATA/etc/ld.so.cache. Or alternatively you could try using symlink instead of bind-file.

1 Like

That’s a good question. I regenerate the file with ldconfig. I guess it must be internally unlinking the file. I’m going to try generating to a temporary file and then catting that into the bound file to see if that fixes it. Thanks for the insights :slight_smile:

1 Like

dont cat, mv is your friend :slight_smile:

switching inodes (which mv does (as long as the file in on the same filesystem)) is a lot faster than shoveling bytes around.

1 Like

Reverting to using a fake-etc and then cp the generated file seems to be working correctly. Thanks all :slight_smile:

https://snapcraft-utils-library.readthedocs.io/en/latest/lib/linker-cache.html now has the working version

1 Like