Re: [PATCH setup 2/2] Improve file:// url handling
On Tue, Mar 06, 2018 at 08:43:47PM +, Jon Turney wrote: > On 28/02/2018 11:51, SZAVAI Gyula wrote: > > [...] > > Most non-standard urls accepted by the old code should work, too. > > Paths longer than 260 characters are not supported anymore. > > Great, thanks! I applied these patches. Thanks. > > @@ -72,11 +74,24 @@ NetIO::open (char const *url, bool cachable) > > else if (strncmp (url, "ftps://", 7) == 0) > > proto = ftps; > > else if (strncmp (url, "file://", 7) == 0) > > -proto = file; > > - else > > { > > proto = file; > > - file_url = (std::string("file://") + url); > > + > > + // WinInet expects a legacy file:// url > > + // (a windows path with "file://" prepended) > > + // > > https://blogs.msdn.microsoft.com/freeassociations/2005/05/19/the-bizarre-and-unhappy-story-of-file-urls/ > > + char path[MAX_PATH]; > > + DWORD len = MAX_PATH; > > + if (S_OK == PathCreateFromUrl(url, path, &len, 0)) > > +{ > > + file_url = std::string("file://") + path; > > + url = file_url.c_str(); > > +} > > If PathCreateFromUrl fails (longer than PATH_MAX?), how intelligibly is that > failure reported? We get the "Unable to get setup from" messagebox and a "connection error: 206" line in setup.log. from https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382%28v=vs.85%29.aspx 206 (0xCE) ERROR_FILENAME_EXCED_RANGE The filename or extension is too long. > I suspect PathCreateFromUrlA is being called here. What happens if there is > a non-ascii character in the URL? It doesn't work, but it didn't work before my changes either. (I've tried 2.889 with greek and chinese directory names, and it has failed.) s
Re: [PATCH setup 2/2] Improve file:// url handling
On 28/02/2018 11:51, SZAVAI Gyula wrote: As a repo url, we're accepting * raw windows paths (with both \ and /) c:\cygwin repo \\machine\share\cygwin repo * proper file: urls file:///c:/cygwin%20repo file://machine/share/cygwin%20repo Most non-standard urls accepted by the old code should work, too. Paths longer than 260 characters are not supported anymore. Great, thanks! I applied these patches. --- netio.cc | 21 ++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/netio.cc b/netio.cc index c8982de..1e784b1 100644 --- a/netio.cc +++ b/netio.cc @@ -25,6 +25,8 @@ #include #include +#include This needs to be lower-case to compile on a case-sensitive system (I think all w32api headers have lower-case names, notwithstanding MS's use of random case on a non-case-sensitive system) + #include "resource.h" #include "state.h" #include "msg.h" @@ -72,11 +74,24 @@ NetIO::open (char const *url, bool cachable) else if (strncmp (url, "ftps://", 7) == 0) proto = ftps; else if (strncmp (url, "file://", 7) == 0) -proto = file; - else { proto = file; - file_url = (std::string("file://") + url); + + // WinInet expects a legacy file:// url + // (a windows path with "file://" prepended) + // https://blogs.msdn.microsoft.com/freeassociations/2005/05/19/the-bizarre-and-unhappy-story-of-file-urls/ + char path[MAX_PATH]; + DWORD len = MAX_PATH; + if (S_OK == PathCreateFromUrl(url, path, &len, 0)) +{ + file_url = std::string("file://") + path; + url = file_url.c_str(); +} If PathCreateFromUrl fails (longer than PATH_MAX?), how intelligibly is that failure reported? I suspect PathCreateFromUrlA is being called here. What happens if there is a non-ascii character in the URL? +} + else // treat everything else as a windows path +{ + proto = file; + file_url = std::string("file://") + url; url = file_url.c_str(); }
[PATCH setup 2/2] Improve file:// url handling
As a repo url, we're accepting * raw windows paths (with both \ and /) c:\cygwin repo \\machine\share\cygwin repo * proper file: urls file:///c:/cygwin%20repo file://machine/share/cygwin%20repo Most non-standard urls accepted by the old code should work, too. Paths longer than 260 characters are not supported anymore. --- netio.cc | 21 ++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/netio.cc b/netio.cc index c8982de..1e784b1 100644 --- a/netio.cc +++ b/netio.cc @@ -25,6 +25,8 @@ #include #include +#include + #include "resource.h" #include "state.h" #include "msg.h" @@ -72,11 +74,24 @@ NetIO::open (char const *url, bool cachable) else if (strncmp (url, "ftps://", 7) == 0) proto = ftps; else if (strncmp (url, "file://", 7) == 0) -proto = file; - else { proto = file; - file_url = (std::string("file://") + url); + + // WinInet expects a legacy file:// url + // (a windows path with "file://" prepended) + // https://blogs.msdn.microsoft.com/freeassociations/2005/05/19/the-bizarre-and-unhappy-story-of-file-urls/ + char path[MAX_PATH]; + DWORD len = MAX_PATH; + if (S_OK == PathCreateFromUrl(url, path, &len, 0)) +{ + file_url = std::string("file://") + path; + url = file_url.c_str(); +} +} + else // treat everything else as a windows path +{ + proto = file; + file_url = std::string("file://") + url; url = file_url.c_str(); } -- 2.16.1