canonical / rockcraft

Tool to create OCI Images using the language from Snapcraft and Charmcraft.
GNU General Public License v3.0
35 stars 43 forks source link

usrmerge handling is not dealing with subdirectories #187

Closed tigarmo closed 1 year ago

tigarmo commented 1 year ago

Our code that archives the lifecycle payload as a new layer is taking the usrmerge into account when handling files, but not when handling subdirectories; So for example, if a part primes two files:

- bin/f1
- lib/subdir/f2

bin/f1 will be correctly archived as usr/bin/f1, but lib/subdir/f2 will stay as lib/subdir/f2, possibly breaking the usrmerge symlink (depends on the version of... something).

Here's a rockcraft.yaml that repros this:

name: usrmerge-dir-bug
base: ubuntu:22.04
version: '0.1'
summary: usrmerge-dir-bug
description: usrmerge-dir-bug
license: GPL-3.0 
platforms:
  amd64:

parts:
  p1:
    plugin: nil
    override-build: |
      cd ${CRAFT_PART_INSTALL}

      mkdir bin
      touch bin/f1

      mkdir -p lib/subdir
      touch lib/subdir/f2

Building it and then loading it in dive shows the issue; see on the right the lib entry has no permissions - that's the tell that it's broken:

image

The build log shows it too:

2023-02-07 16:02:11.359 :: 2023-02-07 19:02:10.607 Creating new layer
2023-02-07 16:02:11.359 :: 2023-02-07 19:02:10.608 Skipping /root/prime/bin because it exists as a symlink on the lower layer
2023-02-07 16:02:11.359 :: 2023-02-07 19:02:10.608 Adding to layer: /root/prime/bin/f1 as 'usr/bin/f1'
2023-02-07 16:02:11.359 :: 2023-02-07 19:02:10.614 Skipping /root/prime/lib because it exists as a symlink on the lower layer
2023-02-07 16:02:11.359 :: 2023-02-07 19:02:10.614 Adding to layer: /root/prime/lib/subdir
2023-02-07 16:02:11.359 :: 2023-02-07 19:02:10.615 Adding to layer: /root/prime/lib/subdir/f2 as 'lib/subdir/f2'
tigarmo commented 1 year ago

fixed by #200