Description
What version of Go are you using (go version
)?
all /up to 1.10
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (go env
)?
all
What did you do?
Using filepath.Join
or filepath.EvalSymlinks
What did you expect to see?
I expected those functions to transform valid file paths to still valid file paths
What did you see instead?
Completely corrupted file paths if the path contains a symbolic link to a directory
General Description
The first time I observed a strange behaviour was by using terraform. terrform switched to the
use of filepath.EvalSymlinks
. Afterwards my terraform project using symbolic links was completely corrupted. Later I wanted to use this function in my own coding, with the same strange results.
An analysis of the filepath package yields something I couldn't believe:
The package defines a function Clean
that formally normalizes a file path by eliminating ..
and .
entries. As described in the documentation this is done WITHOUT observing the actual file system. Although this is no problem for the function itself, because it is designed to do so, it becomes a severe problem for the whole package, because NEARLY ALL functions internally use Clean
to clean the path even on intermediate results. As a consequence even functions like Join
may deliver corrupted invalid results for valid inputs if the path incorporates symbolic links to directories. Especially EvalSymlinks
cannot be used to evaluate paths to existing files, because Clean
is internally used to normalize content of symbolic links.
Therefore I had to switch to a modified implementation solving this problem.