# HG changeset patch # User Markus Mützel # Date 1654294078 -7200 # Node ID d33af4594440e67ef1f35e9919f2f4bd824701a5 # Parent 505ec2f4e16fcbcf93d7298979277875f51b0d28 __wglob__: Handle patterns with UNC paths on Windows (bug #62576). * liboctave/util/oct-glob.cc (windows_glob): Take portion until first file component for first step when recursing into UNC path patterns. diff -r 505ec2f4e16f -r d33af4594440 liboctave/util/oct-glob.cc --- a/liboctave/util/oct-glob.cc Fri Jun 03 08:52:53 2022 +0200 +++ b/liboctave/util/oct-glob.cc Sat Jun 04 00:07:58 2022 +0200 @@ -253,15 +253,33 @@ if (xpat.empty ()) continue; + std::string dir = ""; + // separate component until first file separator std::size_t sep_pos = xpat.find_first_of (sys::file_ops::dir_sep_chars ()); + + // handle UNC paths + if (sep_pos == 0 && xpat.length () > 1 + && sys::file_ops::is_dir_sep (xpat[1])) + { + // start pattern with a file, i.e., "\\SERVER\share\file" + sep_pos = xpat.find_first_of (sys::file_ops::dir_sep_chars (), 2); + if (sep_pos != std::string::npos) + sep_pos = xpat.find_first_of (sys::file_ops::dir_sep_chars (), + sep_pos + 1); + if (sep_pos != std::string::npos) + { + dir = xpat.substr(0, sep_pos); + xpat = xpat.substr (sep_pos+1); + sep_pos = xpat.find_first_of (sys::file_ops::dir_sep_chars ()); + } + } + std::string file = (sep_pos != std::string::npos) ? xpat.substr (sep_pos) : ""; xpat = xpat.substr (0, sep_pos); - std::string dir = ""; - if ((sep_pos == 2 || xpat.length () == 2) && xpat[1] == ':') { // include disc root with first file or folder