Fall back to hard link when symlink creation lacks privilege#6270
Fall back to hard link when symlink creation lacks privilege#6270rich-purnell wants to merge 2 commits into
Conversation
|
@microsoft-github-policy-service agree |
Trenly
left a comment
There was a problem hiding this comment.
The uninstall flow may need to account for hard links with this change. Tests should be added to validate hardlink creation, path resolution, and removal.
What happens in the upgrade scenario where a hardlink exists but the user now has symlink permissions - does it stay a hardlink, or should it be replaced with a symlink?
2d97bd6 to
2f8b7f5
Compare
I see that in the current installation flow, before creating a symlink, |
📖 Description
When WinGet runs without administrator privileges or Developer Mode enabled,
std::filesystem::create_symlink()fails with the error:This happens because creating symbolic links requires the
SeCreateSymbolicLinkPrivilege, which is only granted to administrators or available when Developer Mode is turned on. While WinGet typically runs with those privileges, there are scenarios where they are not held — for example, when running as a standard user or in a restricted environment.I wrote a local test program that confirmed this behavior. Under those conditions,
std::filesystem::create_symlink(target, link)fails with the above error, butstd::filesystem::create_hard_link(target, link)succeeds. Since a hard link provides identical file resolution behavior for this use case (pointing to the same file on disk), it is a viable fallback.This change adds a fallback: when symlink creation fails specifically with
ERROR_PRIVILEGE_NOT_HELD, the code attempts a hard link instead before returningfalse.Such a change may not solve all problems (for example, in some special file system structures), but it can reduce the impact scope.
🔗 References
Resolves #6058
🔍 Validation
Build succeeds with no errors or warnings.
✅ Checklist
📋 Issue Type
Microsoft Reviewers: Open in CodeFlow