File.exists? on windows

Hello. I have a test that fails on GitHub under windows. I have no windows running. Could someone with window check:

iex(1)> File.mkdir("bar")
iex(2)> File.touch("baz")
iex(3)> File.exists?("bar/../baz")
iex(4)> File.exists?("baz/../bar")

It seems under windows File.exists? returns true for both calls.

You have a file called baz and a directory called bar in the current directory and you’re checking if you a file called baz and a directory called bar in the current directory. Shouldn’t both return true?

If there’s a difference it will be around how the parent directory is resolved for a nonexistent directory, no?

1 Like

Yes, the point is that we get a different result when the code runs on windows.

# on unix
false = File.exists?("baz/../bar")
# on windows
true = File.exists?("baz/../bar")

The question is whether this is expected.

The BEAM file server eventually calls get_full_path in win_prim_file.c to turn the input string into an absolute path and and resolve .. / UNC paths / etc:

That uses the Win32 API GetFullPathNameW which specifically calls out this kind of situation in its docs:

This function does not verify that the resulting path and file name are valid, or that they see an existing file on the associated volume.

There’s no equivalent code in unix_prim_file.c, FWIW