Mercurial > octave
changeset 28054:372f42f122bd
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.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Sun, 09 Feb 2020 22:25:36 +0100 |
parents | b70b9eaaf751 |
children | 713dc97d887f |
files | liboctave/system/file-stat.cc |
diffstat | 1 files changed, 18 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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 ();