fix: handle broken symlinks in shared lib hard_link step#159
Merged
eugenehp merged 1 commit intoeugenehp:mainfrom Apr 3, 2026
Merged
fix: handle broken symlinks in shared lib hard_link step#159eugenehp merged 1 commit intoeugenehp:mainfrom
eugenehp merged 1 commit intoeugenehp:mainfrom
Conversation
On Linux, cmake creates versioned symlink chains for shared libraries (e.g. libllama.so -> libllama.so.0 -> libllama.so.0.0.445). When the library version changes between builds, old symlinks become broken. Path::exists() returns false for broken symlinks, but hard_link() fails with EEXIST because the directory entry still exists. This causes panics on rebuild when using dynamic-link feature on Linux. Fix: use symlink_metadata() to detect any existing entry (including broken symlinks) and remove it before creating the hard link.
Owner
|
Good catch, been testing this over the CI mostly. Going to add to the next release. |
eugenehp
added a commit
that referenced
this pull request
Apr 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Linux, cmake creates versioned symlink chains for shared libraries:
When the library version changes between builds, old symlinks in
target/debug/become broken (dangling). The current code checksif !dst.exists()before callinghard_link(), butPath::exists()returnsfalsefor broken symlinks — even though the directory entry still exists.hard_link()then fails withEEXIST, causing a panic on rebuild.This affects any Linux user with the
dynamic-linkfeature enabled.Fix
Use
symlink_metadata()instead ofexists()to detect any existing entry (including broken symlinks), and remove it before creating the hard link. Extracted into aforce_hard_linkclosure to avoid duplication across the three copy sites.Testing
Tested on Arch Linux (CachyOS) with:
cargo build(clean) — workscargo build(rebuild, symlinks present) — works (previously panicked)dynamic-linkfeature) — unaffected, code path not reached