Mercurial > octave
diff libinterp/corefcn/load-path.cc @ 27703:12a53552db92
Use Unicode-aware functions when initializing load-path (bug #57235).
* load-path.cc (load_path::dir_info::get_file_list): The "dir_entry" class
cannot handle non-ASCII characters in paths cross-platform. Use "get_dirlist"
instead.
* dir-ops.h: Add note that using this class can cause issues on Windows.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Sat, 16 Nov 2019 17:24:41 +0100 |
parents | 51d26dd80828 |
children | 7a45100a40c4 |
line wrap: on
line diff
--- a/libinterp/corefcn/load-path.cc Sat Nov 16 16:13:07 2019 +0100 +++ b/libinterp/corefcn/load-path.cc Sat Nov 16 17:24:41 2019 +0100 @@ -1398,69 +1398,66 @@ void load_path::dir_info::get_file_list (const std::string& d) { - sys::dir_entry dir (d); - - if (dir) + string_vector flist; + std::string msg; + + if (! sys::get_dirlist (d, flist, msg)) { - string_vector flist = dir.read (); - - octave_idx_type len = flist.numel (); - - all_files.resize (len); - fcn_files.resize (len); - - octave_idx_type all_files_count = 0; - octave_idx_type fcn_files_count = 0; - - for (octave_idx_type i = 0; i < len; i++) + warning ("load_path: %s: %s", d.c_str (), msg.c_str ()); + return; + } + + octave_idx_type len = flist.numel (); + + all_files.resize (len); + fcn_files.resize (len); + + octave_idx_type all_files_count = 0; + octave_idx_type fcn_files_count = 0; + + for (octave_idx_type i = 0; i < len; i++) + { + std::string fname = flist[i]; + + std::string full_name = sys::file_ops::concat (d, fname); + + sys::file_stat fs (full_name); + + if (fs) { - std::string fname = flist[i]; - - std::string full_name = sys::file_ops::concat (d, fname); - - sys::file_stat fs (full_name); - - if (fs) + if (fs.is_dir ()) { - if (fs.is_dir ()) - { - if (fname == "private") - get_private_file_map (full_name); - else if (fname[0] == '@') - get_method_file_map (full_name, fname.substr (1)); - else if (fname[0] == '+') - get_package_dir (full_name, fname.substr (1)); - } - else + if (fname == "private") + get_private_file_map (full_name); + else if (fname[0] == '@') + get_method_file_map (full_name, fname.substr (1)); + else if (fname[0] == '+') + get_package_dir (full_name, fname.substr (1)); + } + else + { + all_files[all_files_count++] = fname; + + size_t pos = fname.rfind ('.'); + + if (pos != std::string::npos) { - all_files[all_files_count++] = fname; - - size_t pos = fname.rfind ('.'); - - if (pos != std::string::npos) + std::string ext = fname.substr (pos); + + if (ext == ".m" || ext == ".oct" || ext == ".mex") { - std::string ext = fname.substr (pos); - - if (ext == ".m" || ext == ".oct" || ext == ".mex") - { - std::string base = fname.substr (0, pos); - - if (valid_identifier (base)) - fcn_files[fcn_files_count++] = fname; - } + std::string base = fname.substr (0, pos); + + if (valid_identifier (base)) + fcn_files[fcn_files_count++] = fname; } } } } - - all_files.resize (all_files_count); - fcn_files.resize (fcn_files_count); } - else - { - std::string msg = dir.error (); - warning ("load_path: %s: %s", d.c_str (), msg.c_str ()); - } + + all_files.resize (all_files_count); + fcn_files.resize (fcn_files_count); } void