Mercurial > octave
changeset 28051:087a21522aa3
Support canonicalize_file_name on UNC paths (bug #57439).
* file-ops.cc (canonicalize_file_name): Gnulib's canonicalize_file_name doesn't
work with files on UNC shares. Try to canonicalize these file names anyway.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Sat, 08 Feb 2020 09:38:16 +0100 |
parents | 04b2977952cc |
children | 118606de9359 |
files | liboctave/system/file-ops.cc |
diffstat | 1 files changed, 31 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/system/file-ops.cc Sat Feb 08 08:34:56 2020 +0100 +++ b/liboctave/system/file-ops.cc Sat Feb 08 09:38:16 2020 +0100 @@ -711,14 +711,37 @@ #endif #if defined (OCTAVE_USE_WINDOWS_API) - // Get a more canonical name wrt case and full names - std::wstring w_tmp = L"\\\\?\\" + u8_to_wstring (retval); - wchar_t w_long[32767] = L""; - int w_len = GetLongPathNameW (w_tmp.c_str (), w_long, 32767); - if (w_len > 4) - retval = u8_from_wstring (std::wstring (w_long+4, w_len-4)); - if (retval[1] == ':') - retval[0] = toupper (retval[0]); + std::wstring w_tmp; + bool strip_marker = true; + if (retval.empty ()) + { + // For UNC paths, take the input as is. + // Also translate forward slashes. + retval = name; + std::replace (retval.begin (), retval.end (), '/', '\\'); + if (retval.compare (0, 2, "\\\\") == 0) + { + w_tmp = u8_to_wstring (retval); + strip_marker = false; + } + } + else + w_tmp = L"\\\\?\\" + u8_to_wstring (retval); + + if (! w_tmp.empty ()) + { + // Get a more canonical name wrt case and full names + wchar_t w_long[32767] = L""; + int w_len = GetLongPathNameW (w_tmp.c_str (), w_long, 32767); + + if (! strip_marker) + retval = u8_from_wstring (std::wstring (w_long, w_len)); + else if (w_len > 4) + retval = u8_from_wstring (std::wstring (w_long+4, w_len-4)); + + if (retval.length () > 1 && retval[1] == ':') + retval[0] = toupper (retval[0]); + } #endif if (retval.empty ())