← 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

Organize was changed to preserve existing destination files; the fix merged in snapcraft#780 as commit 8386479e7.

Resolution: closed resolved

Reason: PR #780, “Organize without removing files on target,” implemented the fix and was merged as commit 8386479e7.

Evaluated by: mr-cal-bot

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
stealth/space-bunny-alpha — closed resolved Organize was changed to preserve existing destination files; the fix merged in snapcraft#780 as commit 8386479e7.
stealth/space-bunny-alpha — closed resolved Fixed by merged PR canonical/snapcraft#780 (8386479e7), making organize preserve existing destination files and directories instead of deleting them.
stealth/space-bunny-alpha — closed resolved Fixed by merged PR #780 (commit 8386479e7): organize now preserves existing destination files and directories instead of deleting them.
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

Date Change
created

Related work

  • Likely Fixed By: snapcraft#780 (confidence 100%)

    Merged commit 8386479e7 changed organize behavior so destination files are no longer removed.

Related issues

Issue Project State Summary Similarity
#1370 fix: make sure the destination does not exist before organizing craft-parts merged Merged PR #1370 as commit 7fe7c84e, removing any existing organize destination before moving files and fixing #1366/CRAFT-4870.
76%
#1794083 Updating build with organize can result in "destination path already exists" snapcraft (launchpad) closed Fixed in snapcore/snapcraft#2290 (commit 2cef6c3f6), making update builds overwrite prior organize output; #2305 was linked as the 18.10 follow-up.
73%
#1535 feat: organize files from build craft-parts merged Merged as 8e4daf5 adding (build)-partition organize support and trailing-slash destination handling for #1521; reverted by #1548 (56282732) after a Snapcraft regression, then re-landed as #1598.
71%