repo: address issue with fix_symlink() when pointed at directory
Metadata
Current evaluation
Merged fix addressing fix_symlink() crashes when targeting directories. Updates behavior to warn about dangling symlinks, includes refactoring and documentation, and was approved by reviewers prior to merge.
Suggested action: —
No scores available.
Issue body
repo: address issue with fix_symlink() when pointed at directory
If target is a directory, simply warn about dangling symlink.
Light refactoring to make it easier to follow and add documentation.
Example:
```
name: test
base: core18
version: '0.1'
summary: Single-line
description: |
Bla Bla
grade: stable
confinement: strict
parts:
my-part:
# See 'snapcraft plugins'
source: stuff
plugin: nil
stage-packages:
- openssl
- jq
override-build: |
# Create some host files to use.
mkdir -p /tmp/d1
touch /tmp/f1
ln -sf /tmp/d1 /tmp/sd1
ln -sf /tmp/f1 /tmp/sf1
# Symlink from part install to host files.
ln -sf /tmp/d1 $SNAPCRAFT_PART_INSTALL/d1
ln -sf /tmp/f1 $SNAPCRAFT_PART_INSTALL/f1
ln -sf /tmp/sd1 $SNAPCRAFT_PART_INSTALL/sd1
ln -sf /tmp/sf1 $SNAPCRAFT_PART_INSTALL/sf1
ln -sf /tmp/does-not-exist $SNAPCRAFT_PART_INSTALL/does-not-exist
# Similar for build dir.
touch $SNAPCRAFT_PART_BUILD/file
ln -sf $SNAPCRAFT_PART_BUILD/build-file $SNAPCRAFT_PART_INSTALL/build-file
```
Run:
```
$ mkdir stuff
s snapcraft
$ touch stuff/foo
$ snapcraft
```
Previously, with the directories, snapcraft would fail:
```
File "/home/ubuntu/snapcraft/snapcraft/internal/repo/_deb.py", line 427, in unpack_stage_packages
cls.normalize(str(install_path))
File "/home/ubuntu/snapcraft/snapcraft/internal/repo/_base.py", line 204, in normalize
cls._fix_artifacts(unpackdir)
File "/home/ubuntu/snapcraft/snapcraft/internal/repo/_base.py", line 252, in _fix_artifacts
cls._fix_symlink(path, unpackdir, root)
File "/home/ubuntu/snapcraft/snapcraft/internal/repo/_base.py", line 287, in _fix_symlink
if not os.path.exists(target) and not _try_copy_local(path, target):
File "/home/ubuntu/snapcraft/snapcraft/internal/repo/_base.py", line 311, in _try_copy_local
shutil.copyfile(os.readlink(path), target)
File "/usr/lib/python3.6/shutil.py", line 120, in copyfile
with open(src, 'rb') as fsrc:
```
Now, the re-build will trigger the following messages:
'build-file' will be a dangling symlink
'does-not-exist' will be a dangling symlink
'd1' will be a dangling symlink
'sd1' will be a dangling symlink'
The rebuild is required to activate teh fix_symlink() on the assets
already in $SNAPCRAFT_PART_INSTALL. Snapcraft either needs to ensure
that these checks are run only on installed files from the deb (the
original intention), or as a complete pass on build/stage/prime to
ensure consistency. This does not address that.
Fixes SNAPCRAFT-2AV
Signed-off-by: Chris Patterson <chris.patterson@canonical.com>
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| qwen/qwen3.6-35b-a3b | — | — | Merged fix addressing fix_symlink() crashes when targeting directories. Updates behavior to warn about dangling symlinks, includes refactoring and documentation, and was approved by reviewers prior to merge. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Merged fix for fix_symlink() directory target crash. Now warns about dangling symlinks instead of failing. Includes refactoring and docs. Reviewer requested additional test coverage for symlink paths. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Merged fix for fix_symlink() crash on directory targets. Now warns about dangling symlinks instead of failing. Includes refactoring and docs to resolve SNAPCRAFT-2AV, though reviewer requested more test coverage. |
Update history
No update history recorded yet.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #3497 repo: fix regression in fix_symlink() | snapcraft | merged | Merged a fix for a regression in fix_symlink() where copied files retained stale symlinks. The update ensures symlinks correctly point to new files and adds spread tests for relative and host copy scenarios. Approved by two reviewers and passed CI. | |
| #131 Respect the symlink even if it's a directory when building. | charmcraft | merged | Merged a pull request updating the build process to respect symlinks pointing to directories. Approved by three reviewers, passed CI checks, and modified two files with 85 additions and 15 deletions. | |
| #1100 fix(remotebuild): allow building projects with dangling symlinks | craft-application | closed | Superseded by an alternative PR. The author closed this dangling symlink fix without merging, opting for @bepri's approach to avoid unmocking tests and unnecessary refactoring. | |
| #377 Correct local source pulling | snapcraft | merged | Merged fix for local source pulling that incorrectly followed symlinks, causing rmdir failures and duplicate pull errors. The change inverts the directory check, adds explicit symlink validation, and improves error handling. Approved by @zyga. Resolves LP: #1558446. | |
| #117 fix: skip symlinks in md5sums | debcraft | merged | Merged a fix that skips symlinks in md5sums. Approved by two reviewers, the change modifies two files with six added lines. CI checks passed aside from a non-blocking OSV-scanner failure. |