# HG changeset patch # User Markus Mützel # Date 1655746281 -7200 # Node ID b47bf773c5084c285f02adf56defa942ca57fc2b # Parent a30f6c08d7b5b9775666c0bfa8e48d5ff4eaf85b 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. diff -r a30f6c08d7b5 -r b47bf773c508 liboctave/system/file-ops.cc --- 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 #if defined (OCTAVE_USE_WINDOWS_API) +# include + # include # 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