Make a path absolute, normalize the path, and remove as many indirections
from it as possible. Any trailing path separators are discarded via
dropTrailingPathSeparator. Additionally, on Windows the letter case of
the path is canonicalized.
Note: This function is a very big hammer. If you only need an absolute path, makeAbsolute is sufficient for removing dependence on the current working directory.
Indirections include the two special directories . and .., as well as
any symbolic links (and junction points on Windows). The input path need
not point to an existing file or directory. Canonicalization is performed
on the longest prefix of the path that points to an existing file or
directory. The remaining portion of the path that does not point to an
existing file or directory will still be normalized, but case
canonicalization and indirection removal are skipped as they are impossible
to do on a nonexistent path.
Most programs should not worry about the canonicity of a path. In particular, despite the name, the function does not truly guarantee canonicity of the returned path due to the presence of hard links, mount points, etc.
If the path points to an existing file or directory, then the output path shall also point to the same file or directory, subject to the condition that the relevant parts of the file system do not change while the function is still running. In other words, the function is definitively not atomic. The results can be utterly wrong if the portions of the path change while this function is running.
Since some indirections (symbolic links on all systems, .. on non-Windows
systems, and junction points on Windows) are dependent on the state of the
existing filesystem, the function can only make a conservative attempt by
removing such indirections from the longest prefix of the path that still
points to an existing file or directory.
Note that on Windows parent directories .. are always fully expanded
before the symbolic links, as consistent with the rest of the Windows API
(such as GetFullPathName). In contrast, on POSIX systems parent
directories .. are expanded alongside symbolic links from left to right.
To put this more concretely: if L is a symbolic link for R/P, then on
Windows L\.. refers to ., whereas on other operating systems L/..
refers to R.
Similar to System.FilePath.normalise, passing an empty path is equivalent
to passing the current directory.
canonicalizePath can resolve at least 64 indirections in a single path,
more than what is supported by most operating systems. Therefore, it may
return the fully resolved path even though the operating system itself
would have long given up.
On Windows XP or earlier systems, junction expansion is not performed due
to their lack of GetFinalPathNameByHandle.
Changes since 1.2.3.0: The function has been altered to be more robust and has the same exception behavior as makeAbsolute.
Changes since 1.3.0.0: The function no longer preserves the trailing path separator. File symbolic links that appear in the middle of a path are properly dereferenced. Case canonicalization and symbolic link expansion are now performed on Windows.