comparison liboctave/util/oct-glob.cc @ 30979:302faf5bc425 stable

__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414). * liboctave/util/oct-glob.cc (find_files): Retain "." and ".." literally in result. * libinterp/corefcn/dirfns.cc (F__wglob__): Add tests. Move test for "Fglob" immediately below function definition.
author Markus Mützel <markus.muetzel@gmx.de>
date Thu, 05 May 2022 19:23:06 +0200
parents 796f54d4ddbf
children 8475b51b990c
comparison
equal deleted inserted replaced
30975:791bc376f979 30979:302faf5bc425
155 155
156 static void 156 static void
157 find_files (std::list<std::string>& dirlist, const std::string& dir, 157 find_files (std::list<std::string>& dirlist, const std::string& dir,
158 const std::string& pat, std::string& file) 158 const std::string& pat, std::string& file)
159 { 159 {
160 if (! pat.compare (".") || ! pat.compare (".."))
161 {
162 // shortcut for trivial patterns that would expand to a folder name
163
164 // get next component of path (or file name)
165 std::size_t sep_pos
166 = file.find_first_of (sys::file_ops::dir_sep_chars ());
167 std::string pat_str = file.substr (0, sep_pos);
168 std::string file_str = (sep_pos != std::string::npos
169 && file.length () > sep_pos+1)
170 ? file.substr (sep_pos+1) : "";
171
172 // call this function recursively with next path component in PAT
173 find_files (dirlist, sys::file_ops::concat (dir, pat),
174 pat_str, file_str);
175 return;
176 }
177
160 // remove leading file separators 178 // remove leading file separators
161 while (file.length () > 1 && sys::file_ops::is_dir_sep (file[0])) 179 while (file.length () > 1 && sys::file_ops::is_dir_sep (file[0]))
162 file = file.substr (1, std::string::npos); 180 file = file.substr (1, std::string::npos);
163 181
164 // find first file in directory that matches pattern in PAT 182 // find first file in directory that matches pattern in PAT
176 { 194 {
177 std::string found_dir = u8_from_wstring (ffd.cFileName); 195 std::string found_dir = u8_from_wstring (ffd.cFileName);
178 196
179 if (file.empty ()) 197 if (file.empty ())
180 { 198 {
199 // Don't include "." and ".." in matches.
181 if (found_dir.compare (".") && found_dir.compare ("..")) 200 if (found_dir.compare (".") && found_dir.compare (".."))
182 dirlist.push_back (sys::file_ops::concat (dir, found_dir)); 201 dirlist.push_back (sys::file_ops::concat (dir, found_dir));
183 } 202 }
184 else 203 else
185 { 204 {