-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Windows] Long-filename problem #8361
Comments
Changing from |
We can still use similar code like (untested): int curlx_open (const char *file, int flags)
{
#ifdef _WIN32
if (strlen(file) >= MAX_PATH) {
wchar_t w_file [32*1024 + 1];
snwprintf(w_file sizeof(w_file)/2, L"\\\\?\\%S", file);
return _wopen(w_file, flags);
}
#elif defined(__VMS)
...
#endif
return open(file, flags);
} But how to report this true file-name ( |
Windows has never worked right with long paths 260+ characters created with
Most of the time the user is going to pass something informal like -o foo or -o ..\bar or even -o c:/baz/qux. None of those will be understood at the lower levels without OS interpretation. In other words I tried
There's already Windows curlx file functions for opening Unicode file names. My gripe with the MS CRT is we should not have to make workarounds for long paths or UTF-8 it should just support it. Otherwise we end up with a bunch of things we constantly have to maintain with ever more hacks as users report problems and I just don't like that. |
I already had the So just changing my .bat file to say So I agree, it's a messy situation with many such APIs in Windows. |
Long Path works on windows 10 v1607 and upwards with opt-in. build File name must be
Users must Set Long Path Aware On system wide through Registry : Why System Wide Long Path is not on by default (?) according to a MS engineer : microsoft/WindowsAppSDK#875 (comment) Following APIs change behaviors after opt-in : CopyFileW, CopyFile2, CopyFileExW, CreateFileW, CreateFile2, CreateHardLinkW, CreateSymbolicLinkW, DeleteFileW, FindFirstFileW, FindFirstFileExW, FindNextFileW, GetFileAttributesW, GetFileAttributesExW, SetFileAttributesW, GetFullPathNameW, GetLongPathNameW, MoveFileW, MoveFileExW, MoveFileWithProgressW, ReplaceFileW, SearchPathW, FindFirstFileNameW, FindNextFileNameW, FindFirstStreamW, FindNextStreamW, GetCompressedFileSizeW, GetFinalPathNameByHandleW. Ref: |
Did this end up in any conclusion? Can/should we change anything or do we live with it? |
Fixing this would mean changing the code that uses MAX_PATH and setting long path aware in the manifest. And as I mentioned earlier it wouldn't actually be supported unless the user has set LongPathsEnabled in the registry, and even then there's no guarantee it will work with CRT functions. I'd prefer to document it as a known bug and explain the user may be able to use the \\?\ prefix as a workaround. I'm curious what others think. |
Feel free to ignore everything written below.
No need. MAX_PATH const in the code will remain untouched that's the whole point of manifest. Using manifest won't help only when a library hardcodes 256 char instead of MAX_PATH, neither will using Windows itself will change APIs behaviors upon seeing the manifest for that particular executable. ( that's why the manifest file has to be embedded per executable.) Python, CMD, Windows PowerShell, whole .NET runtime supports long path using the manifest in that way. https://docs.microsoft.com/en-us/archive/blogs/jeremykuhne/net-4-6-2-and-long-paths-on-windows-10#enabling-win32-long-path-support
All CRT functions maps to WinAPI. so the guarantee is there. Python does that. https://stackoverflow.com/questions/5604699/crt-and-win32-api
it might be better to add a line somewhere in the docs that says- "As per microsoft recommended way, Users who wish to use long path must use windows 10 and enable it system wide by going to User may use I will prefer avoiding Not sure relevant or not, even upcoming cygwin v3.4 will be the last supported version on vista, 7, 8 platforms. https://cygwin.com/pipermail/cygwin-announce/2022-January/010438.html |
We use PATH_MAX (MAX_PATH) in tool_doswin for some path buffers when not \\?\ so that code would need to be changed and the manifest changed as well.
There is no guarantee. The restriction has been removed from "common" Windows API functions and that's it. It may work. |
in case it boils down to Manifest not supporting all WinAPI such as with Manifest, when these function supports beyond MAX_PATH buffer, application authors won't have to do anything and they will get benefit automatically in future windows versions. therefore I conclude with : |
- Remove PATH_MAX (MAX_PATH, 260) limitations where appropriate. Some PATH_MAX usage remains for MS-DOS specific code. Windows 10 1607 and later supports long paths (ie paths longer than MAX_PATH, up to 32k) if the user opts in via LongPathsEnabled registry key and the application supports it (ie app code not limited by MAX_PATH and app manifest contains attribute ws2:longPathAware). This change addresses all the use of PATH_MAX in the curl tool that would prevent adding ws2:longPathAware to the manifest. However, it does not actually add the attribute. That would have to be a separate change for each build system to create/amend a manifest with that attribute. Prior to this change long paths could be accessed only via the literal path prefix \\?\ (eg \\?\C:\reallylongpath) which bypassed some MAX_PATH checks in both the curl tool and the Windows API. That can still be used as a workaround with the curl tool in all versions of Windows, though the behavior is not guaranteed. It's my opinion that, in general, long path support is not guaranteed to work properly 100% of the time even if we make all the appropriate changes. Refer to the bug discussion for more information. Ref: https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation Bug: curl#8361 Reported-by: Gisle Vanem Closes #xxxx
- Remove PATH_MAX (MAX_PATH, 260) limitations where appropriate. Some PATH_MAX usage remains for MS-DOS specific code. Windows 10 1607 and later supports long paths (ie paths longer than MAX_PATH, up to 32k) if the user opts in via LongPathsEnabled registry key and the application supports it (ie app code not limited by MAX_PATH and app manifest contains attribute ws2:longPathAware). This change addresses all the use of PATH_MAX in the curl tool that would prevent adding ws2:longPathAware to the manifest. However, it does not actually add the attribute. That would have to be a separate change for each build system to create/amend a manifest with that attribute. Prior to this change long paths could be accessed only via the literal path prefix \\?\ (eg \\?\C:\reallylongpath) which bypassed some MAX_PATH checks in both the curl tool and the Windows API. That can still be used as a workaround with the curl tool in all versions of Windows, though the behavior is not guaranteed. It's my opinion that, in general, long path support is not guaranteed to work properly 100% of the time even if we make all the appropriate changes. Refer to the bug discussion for more information. Ref: https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation Bug: curl/curl#8361 Reported-by: Gisle Vanem Closes #xxxx
Let's document this as a known bug/limitation, especially since nobody is working on addressing it. Anyone feels inclined to write up a description ? |
Bug: curl#8361 Reported-by: Gisle Vanem Closes #xxxx
This issue has been documented as known bug 5.13. |
Bug: curl/curl#8361 Reported-by: Gisle Vanem Closes curl/curl#9288
Bug: curl/curl#8361 Reported-by: Gisle Vanem Closes curl/curl#9288
Bug: curl/curl#8361 Reported-by: Gisle Vanem Closes curl/curl#9288
Bug: curl/curl#8361 Reported-by: Gisle Vanem Closes curl/curl#9288
Bug: curl/curl#8361 Reported-by: Gisle Vanem Closes curl/curl#9288
Bug: curl/curl#8361 Reported-by: Gisle Vanem Closes curl/curl#9288
Bug: curl/curl#8361 Reported-by: Gisle Vanem Closes curl/curl#9288
Bug: curl/curl#8361 Reported-by: Gisle Vanem Closes curl/curl#9288
Bug: curl/curl#8361 Reported-by: Gisle Vanem Closes curl/curl#9288
Bug: curl/curl#8361 Reported-by: Gisle Vanem Closes curl/curl#9288
Bug: curl/curl#8361 Reported-by: Gisle Vanem Closes curl/curl#9288
Bug: curl/curl#8361 Reported-by: Gisle Vanem Closes curl/curl#9288
Bug: curl/curl#8361 Reported-by: Gisle Vanem Closes curl/curl#9288
Bug: curl/curl#8361 Reported-by: Gisle Vanem Closes curl/curl#9288
Bug: curl/curl#8361 Reported-by: Gisle Vanem Closes curl/curl#9288
Bug: curl/curl#8361 Reported-by: Gisle Vanem Closes curl/curl#9288
Bug: curl/curl#8361 Reported-by: Gisle Vanem Closes curl/curl#9288
Bug: curl/curl#8361 Reported-by: Gisle Vanem Closes curl/curl#9288
Bug: curl/curl#8361 Reported-by: Gisle Vanem Closes curl/curl#9288
Bug: curl/curl#8361 Reported-by: Gisle Vanem Closes curl/curl#9288
Bug: curl/curl#8361 Reported-by: Gisle Vanem Closes curl/curl#9288
Bug: curl/curl#8361 Reported-by: Gisle Vanem Closes curl/curl#9288
Bug: curl/curl#8361 Reported-by: Gisle Vanem Closes curl/curl#9288
Bug: curl/curl#8361 Reported-by: Gisle Vanem Closes curl/curl#9288
Bug: curl/curl#8361 Reported-by: Gisle Vanem Closes curl/curl#9288
Bug: curl/curl#8361 Reported-by: Gisle Vanem Closes curl/curl#9288
Bug: curl/curl#8361 Reported-by: Gisle Vanem Closes curl/curl#9288
Bug: curl/curl#8361 Reported-by: Gisle Vanem Closes curl/curl#9288
Bug: curl/curl#8361 Reported-by: Gisle Vanem Closes curl/curl#9288
- Add a helper function for the Windows file wrapper functions that will normalize a long path (or a filename in a long path) and add the prefix `\\?\` so that Windows will access the file. Prior to this change if a filename (when normalized internally by Windows to its full path) or a path was longer than MAX_PATH (260) then Windows would not open the path, unless it was already normalized by the user and had the `\\?\` prefix prepended. The `\\?\` prefix could not be passed to file:// so for example something like file://c:/foo/bar/filename255chars could not be opened prior to this change. There's some code in tool_doswin that will need to be modified as well to further remove MAX_PATH (aka PATH_MAX) limitation. Ref: curl#8361 Ref: curl#13512 Ref: https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats Ref: https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation Closes #xxxx
- Add a helper function for the Windows file wrapper functions that will normalize a long path (or a filename in a long path) and add the prefix `\\?\` so that Windows will access the file. Prior to this change if a filename (when normalized internally by Windows to its full path) or a path was longer than MAX_PATH (260) then Windows would not open the path, unless it was already normalized by the user and had the `\\?\` prefix prepended. The `\\?\` prefix could not be passed to file:// so for example something like file://c:/foo/bar/filename255chars could not be opened prior to this change. There's some code in tool_doswin that will need to be modified as well to further remove MAX_PATH (aka PATH_MAX) limitation. Ref: curl#8361 Ref: curl#13512 Ref: https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats Ref: https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation Closes #xxxx
- Add a helper function for the Windows file wrapper functions that will normalize a long path (or a filename in a long path) and add the prefix `\\?\` so that Windows will access the file. Prior to this change if a filename (when normalized internally by Windows to its full path) or a path was longer than MAX_PATH (260) then Windows would not open the path, unless it was already normalized by the user and had the `\\?\` prefix prepended. The `\\?\` prefix could not be passed to file:// so for example something like file://c:/foo/bar/filename255chars could not be opened prior to this change. There's some code in tool_doswin that will need to be modified as well to further remove MAX_PATH (aka PATH_MAX) limitation. Ref: curl#8361 Ref: curl#13512 Ref: https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats Ref: https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation Closes #xxxx
There is an issue with access to filenames with >= 260 characters in the Windows version of curl.
I used this
<curl_root>\upload-long-file.bat
file to verify:With a
upload-long-file.bat long
, curl fails to open the%LONG_FILE
:Seems the problem is here which does not support such long-filenames AFAICS.
According to MSDN, this needs CreateFileW() as
"\\?\" + per->uploadfile
.curl/libcurl version
operating system
Windows-10, 21H1, 19043.1503.
[1] From the "Geospatial Data Abstraction Library" project.
The text was updated successfully, but these errors were encountered: