peteraritchie / LongPath

drop-in library to support long paths in .NET
GNU Lesser General Public License v3.0
112 stars 43 forks source link

Directory.Exist return strange result #12

Closed Fabsky closed 9 years ago

Fabsky commented 9 years ago

I'm trying your library. The application is a bit special: it's a namespace extension. At some place, I've this method:

public string CreateFolder(string mirror)
        {
            var local = Path.Combine(this._rootFolder, handleInvalidCharacters(mirror));
            if (!Directory.Exists(local))
                Directory.CreateDirectory(local);
            return local;
        }

This method is called maybe 10x in parallel by windows. The Directory.Exists return true ... but the folder doesn't exists. It's never created.

In VS if I type these commands::

Pri.LongPath.Directory.Exists(local) true System.IO.Directory.Exists(local) false

If I try in a "safe" environment with one simple execution, the method correctly return false

Any idea ? Thank you

Fabsky commented 9 years ago

Here is a screenshot when debugging the source code (Common.cs line 70) The path doesn't exists (the drop folder exists, but not the "Clients _ Quatre" folder) I think the problem comes from the fact that Directory.IsDirectory(-1) return true ?

image

This is the same path, but executed from nunit test:

image

The problem comes from Marshal.GetLastWin32Error(); which return 0 (Common.cs line 114) In a unit test, it returns 2. But in the namespace extension application, it returns 0

Fabsky commented 9 years ago

See https://github.com/peteraritchie/LongPath/pull/13

peteraritchie commented 9 years ago

Still trying to repo, if you could create a unit test gist (or just paste code in the issue) that repros it, that would help me get to it sooner :)

peteraritchie commented 9 years ago

I assume the PR from #13 fixes this