When a symlink is at filesystem root (such can be the case on OSTree
systems where /root points to /var/roothome and /home points to
/var/home) EvalSymlinks fails to follow it correctly. Instead of
following it in the context of the root directory, it tries to follow it
in the context of the current directory.
This is because when the last traversed directory is removed to
concatenate the symlink target, "/home" contract to the empty string,
and "var/home" is thus evaluated in the context of the current
This commit fixes that by detecting if the last removed directory was a
root directory, and does not remove the trailing path separator in that
Unfortunately, I might not be able to provide a pull request with that patch as I don't have a google account at hand to sign the CLA (and I won't create one). Please feel free to do whatever you want with the patch I provide, I do not retain any copyright on it.
What version of Go are you using (
Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
What did you do?
I found a bug in terraform: hashicorp/terraform#25367 and tracked it down to the go runtime
Reproduce by compiling this example and running it:
(you need to be root for chroot to work, it works well in a fedora-toolbox container with a user namespace root)
What did you expect to see?
filepath.EvalSymlinksshould follow symlink
home -> var/homein
What did you see instead?
filepath.EvalSymlinksfails to follow the symlink and errors out with
lstat var: no such file or directory
The text was updated successfully, but these errors were encountered: