Unhandled error when organizing a file to a directory where the file already exists
Metadata
Current evaluation
Fixed by merged PR canonical/craft-parts#1370 (commit 7fe7c84e), which checks whether an organize destination exists before moving files.
Resolution: closed resolved
Reason: PR #1370 was merged and added an existence check for organize destinations before calling move, resolving the swallowed collision error.
Evaluated by: mr-cal-bot
No scores available.
Issue body
### Bug Description
The `organize_files` function in craft-parts does not properly detect collisions when the destination is a directory. If an entry organize a file to a destination and then a second entry also tries to organize to the same destination but expressed as a directory, it fails because the call to `file_utils.move(src,dst)` fails. However this error is not handled and is "swallowed".
The function should probably check if the destination exists when `overwrite` is `False` before calling `file_utils.move(src,dst)`.
### To Reproduce
Running `python3 -mcraft_parts --trace -v prime` with this project file fails with `Error: None`.
### part yaml
```shell
parts:
rootfs:
plugin: nil
override-build: |
mkdir $CRAFT_PART_INSTALL/foo
mkdir $CRAFT_PART_INSTALL/bar
echo "a from foo" > $CRAFT_PART_INSTALL/foo/a
echo "a from bar" > $CRAFT_PART_INSTALL/bar/a
organize:
'bar/a': /qux/a
'foo/a': /qux/
```
### Relevant log output
```shell
INFO:craft_parts.executor.executor:Installing build-packages
Execute: Pull rootfs
Execute: Overlay rootfs
Execute: Build rootfs
+ mkdir /home/paul/scratch/craft-parts/parts/rootfs/install/foo
+ mkdir /home/paul/scratch/craft-parts/parts/rootfs/install/bar
+ echo 'a from foo'
+ echo 'a from bar'
Error: None.
```
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| stealth/space-bunny-alpha | — | closed resolved | Fixed by merged PR canonical/craft-parts#1370 (commit 7fe7c84e), which checks whether an organize destination exists before moving files. | |
| stealth/space-bunny-alpha | — | closed resolved | Fixed by merged PR canonical/craft-parts#1370 (commit 7fe7c84e), which checks for an existing organize destination before moving files, closing CRAFT-4870. | |
| qwen/qwen3.6-35b-a3b | — | — | Abandoned without a public fix. The bug was tracked internally via Jira (CRAFT-4870) to address unhandled errors when organizing files to existing directories. | |
| qwen/qwen3.6-35b-a3b | — | — | Closed and triaged. Reports a silent failure in organize_files when organizing to an existing directory. Synced to Jira for tracking. | |
| qwen/qwen3.6-35b-a3b | — | — | Closed without resolution or linked fix. The unhandled collision error in organize_files when moving files to an existing directory was triaged but remains unresolved. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Closed and tracked internally via Jira ticket CRAFT-4870. No public fix, merge, or resolution details were provided. |
Update history
No update history recorded yet.
Related work
-
Likely Fixed By:
canonical/craft-parts#1370
(confidence 100%)
Merged fix commit 7fe7c84e prevents a file move from targeting an existing organize destination.
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. | |
| #842 Organizing a file into the default partition gives bad error message | craft-parts | closed | Resolved by canonical/craft-parts#1201, merged as ae1de9f6, which handles organize rules targeting a file in its existing location without the misleading self-link error. | |
| #1007 Organize fails with an unhelpful error when attempting to overwrite a file | craft-parts | closed | Closed as stale without a direct fix; the organize-overwrite failure was later fixed by merged PR #1370 (commit 7fe7c84e), ensuring the destination does not exist before moving files. | |
| #673 Organizing files fails if equivalent file already exists | craft-parts | closed | Organize collisions were fixed by PR #689 (commit c349e740), making organize_files() use part install directories instead of cwd-relative paths. | |
| #1260 fix: allow organize to move special files | craft-parts | merged | Merged in canonical/craft-parts#1260 via commit 9f185208, adding a device-aware move helper so organize can move character and block special files. | |
| #1544 fix: prevent organizing a directory into itself | craft-parts | closed | PR #1544 was closed unmerged as incomplete; the solution was replaced by the organize-from-build rework in #1598 (commit cc02958b). |