Mercurial > octave
changeset 31097:b47bf773c508 stable
canonicalize_file_path: Do not translate mapped network drive to UNC path (bug #62576).
* liboctave/system/file-ops.cc (canonicalize_file_name): Revert translation of
root drive of mapped network share to UNC path.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Mon, 20 Jun 2022 19:31:21 +0200 |
parents | a30f6c08d7b5 |
children | 97918dca79ed c415b218307f |
files | liboctave/system/file-ops.cc |
diffstat | 1 files changed, 23 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/system/file-ops.cc Mon Jun 13 14:07:31 2022 -0400 +++ b/liboctave/system/file-ops.cc Mon Jun 20 19:31:21 2022 +0200 @@ -35,6 +35,8 @@ #include <vector> #if defined (OCTAVE_USE_WINDOWS_API) +# include <cctype> + # include <windows.h> # include "unwind-prot.h" #else @@ -733,7 +735,27 @@ // "Normal" paths are prefixed by "\\?\". // UNC paths are prefixed by "\\?\UNC\". if (retval.compare (0, 8, R"(\\?\UNC\)") == 0) - retval = retval.erase (2, 6); + { + retval = retval.erase (2, 6); + + // If the initial path looked like a mapped network drive, replace + // "\\server\share" portion of path with drive root. + if (name[1] == ':') + { + // Find where "share" portion of UNC path ends + std::size_t sep_pos + = retval.find_first_of (file_ops::dir_sep_chars (), 2); + if (sep_pos != std::string::npos) + sep_pos = retval.find_first_of (file_ops::dir_sep_chars (), + sep_pos + 1); + if (sep_pos != std::string::npos) + retval = retval.substr (sep_pos-2); + else + retval.resize (2); // no file component + retval[0] = std::toupper (name[0]); + retval[1] = ':'; + } + } else if (retval.compare (0, 4, R"(\\?\)") == 0) retval = retval.erase (0, 4); #else