On Wednesday, 19 September 2018 at 09:58:30 UTC, Kagamin wrote:
On Wednesday, 19 September 2018 at 06:26:21 UTC, Vladimir Panteleev wrote:
Someone mentioned in this thread that .NET runtime does do the long-path workaround automatically.

AFAIK, CoreFX does, but .net doesn't. .net did its own path normalization and length check, which can be turned off since 4.6.2.

Thanks. I had a quick look. It looks pretty involved. Here are some of the relevant parts:

https://github.com/dotnet/corefx/blob/0566028e42a8f2fa86b8e0dd856d1f13d0fdce05/src/Common/src/CoreLib/System/IO/PathHelper.Windows.cs#L16-L43
https://github.com/dotnet/corefx/blob/0566028e42a8f2fa86b8e0dd856d1f13d0fdce05/src/Common/src/CoreLib/System/IO/PathHelper.Windows.cs#L68-L95
https://github.com/dotnet/corefx/blob/0566028e42a8f2fa86b8e0dd856d1f13d0fdce05/src/Common/src/CoreLib/System/IO/Path.Windows.cs#L37-L63
https://github.com/dotnet/corefx/blob/0566028e42a8f2fa86b8e0dd856d1f13d0fdce05/src/Common/src/CoreLib/System/IO/PathInternal.Windows.cs#L82-L99
https://github.com/dotnet/corefx/blob/0566028e42a8f2fa86b8e0dd856d1f13d0fdce05/src/Common/src/CoreLib/System/IO/PathInternal.Windows.cs#L118-L141

And for example directory deletion:

https://github.com/dotnet/corefx/blob/0566028e42a8f2fa86b8e0dd856d1f13d0fdce05/src/System.IO.FileSystem/src/System/IO/Directory.cs#L296-L300
https://github.com/dotnet/corefx/blob/0566028e42a8f2fa86b8e0dd856d1f13d0fdce05/src/Common/src/Interop/Windows/kernel32/Interop.RemoveDirectory.cs#L19-L23

Some things stood out to me:

- GetFullPathName is documented as also having the MAX_PATH limit, but the framework seems to use it for normalization BEFORE prepending the prefix.

https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfullpathnamea

- GetFullPathName has a big warning on it about how you shouldn't use it in multithreaded programs.

- The code seems to compare the length against 260 characters, but in my tests, the limit is actually about 12 characters shorter. The same file defines MaxShortDirectoryPath = 248, but that constant isn't used anywhere in the code.

Maybe we shouldn't use this as a reference after all...

Reply via email to