-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
Description
File.ResolveLinkTarget doesn't fully resolve a symbolic link created by Kubernetes volume mounts to its full path as realpath in Linux does.
Reproduction Steps
I tried to resolve a symolic link created by Kubernetes ConfigMap Volume Mounting. I mounted a k8s ConfigMap as a volume client-config.json. This is the file structure:
/mnt/oidc/client-config $ ls -al
total 12
drwxrwxrwx 3 root root 4096 Aug 14 07:17 .
drwxr-xr-x 4 root root 4096 Aug 14 07:17 ..
drwxr-xr-x 2 root root 4096 Aug 14 07:17 ..2025_08_14_07_17_19.1395403829
lrwxrwxrwx 1 root root 32 Aug 14 07:17 ..data -> ..2025_08_14_07_17_19.1395403829
lrwxrwxrwx 1 root root 25 Aug 14 07:17 client-config.json -> ..data/client-config.jsonExpected behavior
I would expect that File.ResolveLinkTarget() returns a fully resolved path /mnt/oidc/client-config/..2025_08_14_07_17_19.1395403829/client-config.json.
Please see this command:
/mnt/oidc/client-config $ realpath /mnt/oidc/client-config/client-config.json
/mnt/oidc/client-config/..2025_08_14_07_17_19.1395403829/client-config.jsonActual behavior
Calling the method File.ResolveLinkTarget("/mnt/oidc/client-config/client-config.json", true) returns the resolved path /mnt/oidc/client-config/..data/client-config.json.
The code snippet is quite simple:
Console.WriteLine($"The resolved path is {File.ResolveLinkTarget("/mnt/oidc/client-config/client-config.json", true)}");Regression?
No response
Known Workarounds
I tried another library https://github.com/nemec/pathlib and its API PosixPath.Resolve() could fully resolve the symbolic link.
Configuration
.NET: 9.0.304
OS: Alpine Linux literally using mcr.microsoft.com/dotnet/sdk:9.0-alpine
Architecture: x64
Other information
This is the API doc https://learn.microsoft.com/en-us/dotnet/api/system.io.file.resolvelinktarget?view=net-9.0. It doesn't have too much behavior description.
I'm not sure whether the behavior is desired or not.