Leftover files affecting consecutive runs of "rockcraft pack"
Metadata
Current evaluation
No evaluation has been recorded for this issue yet.
Issue body
I have the following directory structure:
```
$ tree .
.
├── files
│ ├── a.txt
│ └── b.txt
└── rockcraft.yaml
```
And in `rockcraft.yaml` I want to organize those two text files, but I make a typo and point both to `etc/newfiles/a.txt`:
```
name: leftover
summary: Permissions
description: Permissions
license: Apache-2.0
version: "0.0.1"
base: ubuntu:22.04
parts:
default-config:
plugin: dump
source: files
organize:
a.txt: etc/newfiles/a.txt
b.txt: etc/newfiles/a.txt
stage:
- etc/newfiles/a.txt
- etc/newfiles/b.txt
```
`rockcraft pack` then expectedly fails:
```
$ rockcraft -v pack
(...)
:: + cp --archive --link --no-dereference . /root/parts/default-config/install
Failed to organize part 'default-config': trying to organize file 'b.txt' to 'etc/newfiles/a.txt', but 'etc/newfiles/a.txt' already exists.
Traceback (most recent call last):
File "/snap/rockcraft/x1/lib/python3.8/site-packages/rockcraft/parts.py", line 92, in run
aex.execute(action, stdout=stream, stderr=stream)
File "/snap/rockcraft/x1/lib/python3.8/site-packages/craft_parts/executor/executor.py", line 301, in execute
self._executor.execute(actions, stdout=stdout, stderr=stderr)
File "/snap/rockcraft/x1/lib/python3.8/site-packages/craft_parts/executor/executor.py", line 126, in execute
self._run_action(act, stdout=stdout, stderr=stderr)
File "/snap/rockcraft/x1/lib/python3.8/site-packages/craft_parts/executor/executor.py", line 189, in _run_action
handler.run_action(action, stdout=stdout, stderr=stderr)
File "/snap/rockcraft/x1/lib/python3.8/site-packages/craft_parts/executor/part_handler.py", line 160, in run_action
state = handler(step_info, stdout=stdout, stderr=stderr)
File "/snap/rockcraft/x1/lib/python3.8/site-packages/craft_parts/executor/part_handler.py", line 320, in _run_build
self._organize(overwrite=update)
File "/snap/rockcraft/x1/lib/python3.8/site-packages/craft_parts/executor/part_handler.py", line 833, in _organize
organize_files(
File "/snap/rockcraft/x1/lib/python3.8/site-packages/craft_parts/executor/organize.py", line 82, in organize_files
raise errors.FileOrganizeError(
craft_parts.errors.FileOrganizeError: Failed to organize part 'default-config': trying to organize file 'b.txt' to 'etc/newfiles/a.txt', but 'etc/newfiles/a.txt' already exists.
```
However, if I fix the `organize` section and re-run `rockcraft -v pack`, I get another error:
```
:: + cp --archive --link --no-dereference . /root/parts/default-config/install
:: cp: cannot create hard link '/root/parts/default-config/install/./b.txt' to './b.txt': File exists
Failed to run the build script for part 'default-config'.
Traceback (most recent call last):
File "/snap/rockcraft/x1/lib/python3.8/site-packages/craft_parts/executor/step_handler.py", line 134, in _builtin_build
subprocess.run(
File "/snap/rockcraft/x1/usr/lib/python3.8/subprocess.py", line 516, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/root/parts/default-config/run/build.sh']' returned non-zero exit status 1.
```
If I make a "big" change like renaming the rock from `leftover` to `leftover2`, the packing finishes successfully. Thanks!
(cc @cmatsuoka)
Evaluation history
No evaluation history available.