← Back to issue list

organize feature deletes destination folder, is surprising

View original Launchpad issue

Metadata

Project
snapcraft (launchpad)
Number
#1599709
Type
issue
State
closed
Author
~thomir-deactivatedaccount
Labels
Created
Updated
Closed

Current evaluation

Reported that snapcraft's organize feature deletes destination directories before moving files. Closed with zero comments, indicating the issue was abandoned without a fix or resolution.

Suggested action:

No scores available.

Issue body

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.

Evaluation history

Date Model Scores Action Summary
qwen/qwen3.6-35b-a3b Reported that snapcraft's organize feature deletes destination directories before moving files. Closed with zero comments, indicating the issue was abandoned without a fix or resolution.
qwen/qwen3.6-35b-a3b Closed without comments or resolution, effectively abandoned. The reported bug where the organize feature unexpectedly deleted destination directories remains unresolved.

Update history

No update history recorded yet.

Related issues

Issue Project State Summary Similarity
#1794083 Updating build with organize can result in "destination path already exists" snapcraft (launchpad) closed Closed without resolution. Snapcraft's automatic rebuild fails when organize globs map to the same directory twice, causing a path conflict. No fix or follow-up was documented.
72%
#1621980 Organize leaves empty parent directories behind snapcraft (launchpad) open Snapcraft's organize keyword leaves empty parent directories in the snap after moving files, requiring manual stage/snap filtering. Filed by a maintainer in 2015 with a clear reproduction; 0 comments, no labels, no maintainer response in 10 years.
70%
#1663233 Confusing error message for "organize" when source refers to multiples items and destination doesn't end up with / snapcraft (launchpad) open Snapcraft 2.26 (2017) reports a misleading 'already exists' error when an organize glob matches multiple items and the destination lacks a trailing slash; reporter suggests auto-treating the destination as a directory. No maintainer response; code has since moved to craft-parts.
70%