# HG changeset patch # User Markus Mützel # Date 1581283536 -3600 # Node ID 372f42f122bd58243c681b9d92a9974f212325be # Parent b70b9eaaf751ee8f7f7ac664ac2183259e022c36 Support stat on UNC root paths (bug #57776). * file-stat.cc (file_stat::update_internal): Canonicalize path. Remove all trailing backslashes. Add trailing backslash for root paths. diff -r b70b9eaaf751 -r 372f42f122bd liboctave/system/file-stat.cc --- a/liboctave/system/file-stat.cc Sun Feb 09 21:38:36 2020 +0100 +++ b/liboctave/system/file-stat.cc Sun Feb 09 22:25:36 2020 +0100 @@ -36,6 +36,10 @@ #include "stat-wrappers.h" #include "strmode-wrapper.h" +#if defined (OCTAVE_USE_WINDOWS_API) +# include "lo-regexp.h" +#endif + namespace octave { namespace sys @@ -189,12 +193,21 @@ std::string full_file_name = sys::file_ops::tilde_expand (file_name); -#if defined (__WIN32__) - // Remove trailing slash. - if (full_file_name.length () > 1 - && sys::file_ops::is_dir_sep (full_file_name.back ()) - && ! (full_file_name.length () == 3 && full_file_name[1] == ':')) +#if defined (OCTAVE_USE_WINDOWS_API) + full_file_name = sys::canonicalize_file_name (full_file_name); + + // Remove trailing slashes + while (full_file_name.length () > 1 + && sys::file_ops::is_dir_sep (full_file_name.back ())) full_file_name.pop_back (); + + // If path is a root (like "C:" or "\\SERVER\share"), add a + // trailing backslash. + // FIXME: Does this pattern match all possible UNC roots? + octave::regexp pat (R"(^\\\\[\w-]*\\[\w-]*$)"); + if ((full_file_name.length () == 2 && full_file_name[1] == ':') + || pat.is_match (full_file_name)) + full_file_name += "\\"; #endif const char *cname = full_file_name.c_str ();