# HG changeset patch # User Markus Mützel # Date 1655746333 -7200 # Node ID 97918dca79ed83d587e5fcac9a11dd0807843af9 # Parent b6aeea9495317f413061bbc31d24f140fb38c6ab# Parent b47bf773c5084c285f02adf56defa942ca57fc2b maint: Merge stable to default. diff -r b6aeea949531 -r 97918dca79ed liboctave/system/file-ops.cc --- a/liboctave/system/file-ops.cc Wed Jun 15 20:00:35 2022 +0200 +++ b/liboctave/system/file-ops.cc Mon Jun 20 19:32:13 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