os: Readlink should return destination even if link is broken #31996
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
WaitingForInfo
Issue is not actionable because of missing required information, which needs to be provided.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
When reading a symlink with non-existing target the
os.Readlink
will return empty string and error. That makes reading the path of the target impossible.For example, if you are in container and use shared PID namespace (which means you share the
/proc
) and you want to get a PID, one way to do so is to follow the/proc/PID/exe
link.In case of shared PID namespace, if you don't use the same image for containers sharing the
/proc
, it will return broken link (which is OK). Unfortunately,os.Readlink
can't be used to get the destination string.What did you expect to see?
I want to see the destination of a symlink, even when
os.Readlink
is not able to follow the link. It is fine to return the error, but the destination can be returned as well.The caller can decide to ignore (or not to ignore) the returned destination.
There should be no breakage to existing code.
What did you see instead?
The
os.Readlink
return "", error on broken link.The text was updated successfully, but these errors were encountered: