← Back to issue list

Symlink fixing logic doesn't consider relative location changes when using organize

View original Github issue

Metadata

Project
craft-parts
Number
#674
Type
issue
State
open
Author
dilyn-corner
Labels
Created
2024-02-28 00:02:23+00:00
Updated
2025-03-11 14:28:35+00:00
Closed

Current evaluation

No evaluation has been recorded for this issue yet.

Issue body

### Bug Description When staging a debian package which includes a symlink to another location within that debian package, there is an attempt to fix that link: ``` 2024-02-27 18:45:37.303 fix artifacts: unpack_dir='/root/parts/my-part/install' 2024-02-27 18:45:37.304 fix symlink: path='/root/parts/my-part/install/lib/modules/6.5.0-9-generic/build', unpack_dir='/root/parts/my-part/install', root='/root/parts/my-part/install/lib/modules/6.5.0-9-generic' 2024-02-27 18:45:37.387 fix symlink: target='/root/parts/my-part/install/usr/src/linux-headers-6.5.0-9-generic' ``` However, this fix does not take into consideration that the name (location) of the link file may change when using `organize`. Likewise, the fix does not take into consideration that the name (location) of the target file may change when using `organize`. I chose the package I did simply because it was the easiest package I knew of with an important symlink. However, any debian package should work. The relevant code appears to (only?) run in the case where a `stage-package` is specified, and only on that package's contents. (I could not reproduce this behavior with a contrived `source: dir/` part). ### To Reproduce Install snapcraft from latest/stable (used revision 10595) and attempt to build the below `snapcraft.yaml`; I used `snapcraft build my-part --shell-after --verbosity=debug` to do some exploring. Note that I organize two different directories; removing either line in `organize` will result in similarly broken links. ### part yaml ```shell name: my-snap-name # you probably want to 'snapcraft register <name>' base: core22 # the base snap is the execution environment for this snap version: '0.1' # just for humans, typically '1.2+git' or '1.3.2' summary: Single-line elevator pitch for your amazing snap # 79 char long summary description: | This is my-snap's description. You have a paragraph or two to tell the most important story about your snap. Keep it under 100 words though, we live in tweetspace and your description wants to look good in the snap store. grade: devel # must be 'stable' to release into candidate/stable channels confinement: devmode # use 'strict' once you have the right plugs and slots package-repositories: - type: apt components: [main] architectures: [riscv64] suites: [noble, noble-security, noble-updates] key-id: F6ECB3762474EDA9D21B7022871920D1991BC93C url: http://ports.ubuntu.com/ubuntu-ports parts: my-part: # See 'snapcraft plugins' plugin: nil stage-packages: [linux-headers-allwinner:riscv64] organize: usr/src/: src/ lib/modules: modules/ ``` ### Relevant log output ```shell {snippet} 2024-02-27 18:53:33.105 Building my-part 2024-02-27 18:53:33.105 execute action my-part:Action(part_name='my-part', step=Step.BUILD, action_type=ActionType.RUN, reason=None, project_vars=None, properties=ActionProperties(changed_files=None, changed_dirs=None)) 2024-02-27 18:53:33.106 load state file: /root/parts/my-part/state/pull 2024-02-27 18:53:39.349 fix artifacts: unpack_dir='/root/parts/my-part/install' 2024-02-27 18:53:39.349 fix symlink: path='/root/parts/my-part/install/lib/modules/6.5.0-9-generic/build', unpack_dir='/root/parts/my-part/install', root='/root/parts/my-part/install/lib/modules/6.5.0-9-generic' 2024-02-27 18:53:39.379 fix symlink: target='/root/parts/my-part/install/usr/src/linux-headers-6.5.0-9-generic' 2024-02-27 18:53:44.062 remove directory /root/parts/my-part/build 2024-02-27 18:53:44.065 Executing PosixPath('/root/parts/my-part/run/build.sh') 2024-02-27 18:53:47.296 Launching shell on build environment... 2024-02-27 18:53:47.296 Emitter: Pausing control of the terminal snapcraft-my-snap-name-on-amd64-for-amd64-2496258 ../project# cd ../parts/my-part/install/ snapcraft-my-snap-name-on-amd64-for-amd64-2496258 ../parts/my-part/install# ls etc lib modules src usr snapcraft-my-snap-name-on-amd64-for-amd64-2496258 ../parts/my-part/install# ls src/ linux-headers-6.5.0-9-generic linux-riscv-headers-6.5.0-9 snapcraft-my-snap-name-on-amd64-for-amd64-2496258 ../parts/my-part/install# ls usr/ lib share snapcraft-my-snap-name-on-amd64-for-amd64-2496258 ../parts/my-part/install# ls -lh modules/6.5.0-9-generic/ total 1.0K lrwxrwxrwx 1 root root 46 Feb 27 18:53 build -> ../../../usr/src/linux-headers-6.5.0-9-generic snapcraft-my-snap-name-on-amd64-for-amd64-2496258 ../parts/my-part/install# cd modules/6.5.0-9-generic/build bash: cd: modules/6.5.0-9-generic/build: No such file or directory ```

Evaluation history

No evaluation history available.