organize feature deletes destination folder, is surprising

Bug #1599709 reported by Thomi Richards
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Snapcraft
Fix Released
High
Sergio Schvezov

Bug Description

I'm snapping an app that installs python packages to /usr/local/lib/python2.7/dist-packages/, and I want them to be in /usr/lib/... inside the snap.

I think I ought to be able to do this with the following in my snapcraft.yaml:

```
  wxpython:
    plugin: python
    source: whatever
    organize:
      usr/local/lib/: usr/lib/
```

However the following code from snapcraft (pluginhandler.py:326):

```
    def _organize(self):
        organize_fileset = getattr(self.code.options, 'organize', {}) or {}

        for key in organize_fileset:
            src = os.path.join(self.code.installdir, key)
            dst = os.path.join(self.code.installdir, organize_fileset[key])

            os.makedirs(os.path.dirname(dst), exist_ok=True)

            if os.path.exists(dst):
                logger.warning(
                    'Stepping over existing file for organization %r',
                    os.path.relpath(dst, self.code.installdir))
                if os.path.isdir(dst):
                    shutil.rmtree(dst)
                else:
                    os.remove(dst)
            shutil.move(src, dst)
```

...will *delete* the destination (usr/lib) before copying the source files in. This is surprising, to say the least, and I can't think of a situation where this is the intended behavior. I suggest the following logic instead:

 * If source is a directory, walk through all files recursively in src.
  * attempt to copy file to dst, reserving the part of the path after source. If it already exists, error and exit.
 * If source and dest are file paths, attempt to copy src to dest. If the destination file already exists, error and exit.

I don't think the 'organize' feature should ever delete files in the destination. The canonical example of this feature being used seems to be https://github.com/ubuntu/snappy-playpen/blob/master/ffmpeg/snapcraft.yaml which copies a file into 'bin/'. If this snap ever contains a second part with an executable in bin/ then they may get deleted, if they're built before the part with the organize stanza.

summary: - organize feature deleted destination folder, is surprising
+ organize feature deletes destination folder, is surprising
Changed in snapcraft:
status: New → Triaged
importance: Undecided → High
assignee: nobody → Sergio Schvezov (sergiusens)
milestone: none → 2.17
Revision history for this message
Sergio Schvezov (sergiusens) wrote :
Changed in snapcraft:
status: Triaged → Fix Committed
Changed in snapcraft:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.