Skip to content

Fix ResolveLinkTarget for intermediate symlinks - #132042

Open
iamhaseebn wants to merge 1 commit into
dotnet:mainfrom
iamhaseebn:fix-resolvelinktarget-intermediate-symlinks
Open

Fix ResolveLinkTarget for intermediate symlinks#132042
iamhaseebn wants to merge 1 commit into
dotnet:mainfrom
iamhaseebn:fix-resolvelinktarget-intermediate-symlinks

Conversation

@iamhaseebn

Copy link
Copy Markdown

Fixes #118719

ResolveLinkTarget(..., returnFinalTarget: true) followed a symlink chain only when each complete current path was itself a symbolic link. Kubernetes ConfigMap layouts use an intermediate ..data directory symlink, so resolution stopped before reaching the final target.

This change:

  • Resolves relative targets component by component so intermediate symbolic links are followed.
  • Preserves lexical absolute targets and dangling final targets.
  • Retains the existing 40-link traversal limit.
  • Adds shared regression coverage for File, Directory, FileInfo, and DirectoryInfo.

Validation:

  • CoreLib build completed with zero warnings and zero errors.
  • System.IO.FileSystem tests: 9,618 passed, 0 failed, and 59 expected skips.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Aug 8, 2026
@iamhaseebn

Copy link
Copy Markdown
Author

@dotnet-policy-service agree.

@iamhaseebn

Copy link
Copy Markdown
Author

@dotnet-policy-service agree

@teo-tsirpanis

Copy link
Copy Markdown
Contributor

I wonder if this would solve the failures in dotnet/msbuild#14482.

@iamhaseebn

Copy link
Copy Markdown
Author

Thanks for the pointer. I checked the failing Linux and macOS tests in dotnet/msbuild#14482. This change would not fix them: it follows intermediate links after the input path itself has been identified as a symbolic link. In #14482, File.ResolveLinkTarget(Directory.GetCurrentDirectory(), true) is called on the already-resolved physical directory, so it returns null before that traversal is reached. ResolveLinkTarget is therefore not a general realpath replacement for that non-link input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.IO community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File.ResolveLinkTarget(String, Boolean) doesn't fully resolve a symbolic link created by Kubernetes volume mounts to its full path

2 participants