Created attachment 25370 [details]
The test program
The bug appears when you try to verify the existence of a file in a directory, that is a symlink. The symlink may not point to a directory higher in the directory structure, it has to be on another branch. Moreover, you have to use ".." in a path, just after pointing to the directory in question
Steps to reproduce:
1) in the exe directory create the following directory structure:
-> test3 -> test/test2 (test3 is a symlink to test/test2 dir. This structure is crucial)
2) run the attached code.
It checks the existence of "test3/../test3/" directory.
Directory.Exists fails, but Directory.GetFileSystemEntries works (prints the "test_file").
The same code DOES work on another directory structure:
-> test2 -> test (test2 is a symlink to test dir)
Directory.Exists should understand symlinks, and handling of different directory structures should be consistent.
I can reproduce with Mono 188.8.131.52 (2017-10/ce494e3d152)
To reproduce, run following commands:
> mkdir test
> mkdir test/test2
> touch test/test2/test_file
> ln -s test/test2 test3
> csc repro.cs && mono repro.exe
It seems that the lstat() syscall itself does not like that path. The solution may have to be part of mono_portability_find_file_internal()
Directory.Exists does work as expected under .NET Core 2.0.
Candidate fix at https://github.com/mono/mono/pull/6039
Fix merged to master