changeset 31065:d33af4594440 stable

__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.
author Markus Mützel <markus.muetzel@gmx.de>
date Sat, 04 Jun 2022 00:07:58 +0200
parents 505ec2f4e16f
children 74d97efb7573 43974344fe19
files liboctave/util/oct-glob.cc
diffstat 1 files changed, 20 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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