"Failed to stage": Parts X and Y have conflicting files - and I want to keep both

My snapcraft.yaml contains something like this:

parts:
  partA:
    plugin: dump
    source: https://github.com/X/partA.git
    organize:
      dist: partA/dist
  partB:
    plugin: dump
    source: https://github.com/X/partB.git
    organize:
      dist: partB/dist

The repos for parts A and B both contain dist folders, which contain files with similar names. This is in theory fine, since I use organize to put each set of files in a different subdirectory within the final snap. But sure enough, when I try to create the snap, I get

Failed to stage: Parts 'partA' and 'partB' have the following files, but with different contents:
    <list of files>

Snapcraft offers some capabilities to solve this by use of the following keywords:
    - `filesets`
    - `stage`
    - `snap`
    - `organize`

I’m somewhat at a loss as to what the right solution here is here. Most suggestions for dealing with this involve using the stage keyword to “filter out” the offending files. That doesn’t work for me, as I do want to keep all files, that then go into each of the two directories.

It doesn’t seem to me that the stage keyword offers the sort of flexibility I need in order to change the directory name during the stage process itself (which would be the most obvious way around this).

So I suspect that my main option is to use either override-build or override-stage and manually move/copy the two dist directories from the build area, in a way that doesn’t lead to conflicts in the stage area. Is that it? Any better suggestions?

After a bit of experimentation, looks like the following does the job:

parts:
  partA:
    plugin: dump
    source: https://github.com/X/partA.git
    override-build: |
      cp -r $SNAPCRAFT_PART_BUILD/dist $SNAPCRAFT_PART_INSTALL/partA-dist
    organize:
      partA-dist: partA/dist
  partB:
    plugin: dump
    source: https://github.com/X/partB.git
    override-build: |
      cp -r $SNAPCRAFT_PART_BUILD/dist $SNAPCRAFT_PART_INSTALL/partB-dist
    organize:
      partB-dist: partB/dist

By the way, weirdly, override-stage didn’t seem to do it - I was getting the original error, even though I was copying from the two parts’ build directories into two separate directories on stage. It’s as if the normal stage operation was still running, even though I had overridden it.

1 Like

This is strange, if you can write up a small reproducer we would be glad to look into it. I you do not want to write up a simple reproducer, we will look into it anyway but might just take a little longer :slight_smile:

Hi @sergiusens! Thanks for taking a look, and my apologies for not responding sooner!

Here is the source snapcraft.yaml that causes this: https://github.com/ammpio/ammp-app-snap/blob/c3a29e41f6b6b0689c18b13aa82f973dac72cd66/snap/snapcraft.yaml#L63 (at this specific commit in the repo). I’ve linked to the “interesting” lines; i.e. if just including the grafana-status-panel and natel-discrete-panel parts, the error should be reproduced.

This is the corresponding build log: https://launchpadlibrarian.net/444801849/buildlog_snap_ubuntu_bionic_amd64_bd5ecc9eed611d52431ead745d3500cf_BUILDING.txt.gz

In the latest version/master of that repo, I’ve implemented the workaround described above.

Thanks again!
Svet