Mercurial > octave
changeset 27497:5a0543de1e47
Add canonical path when using addpath (bug #56267).
* load-path.cc (Faddpath): Canonicalize path before adding it to the search
path.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Wed, 09 Oct 2019 14:35:03 +0200 |
parents | def608acdfa9 |
children | 1a4defb4dfc2 |
files | libinterp/corefcn/load-path.cc |
diffstat | 1 files changed, 21 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/load-path.cc Sat Sep 21 18:09:29 2019 +0200 +++ b/libinterp/corefcn/load-path.cc Wed Oct 09 14:35:03 2019 +0200 @@ -2544,18 +2544,37 @@ }), dir.end ()); + bool is_absolute_path = octave::sys::env::absolute_pathname (dir); + + std::string canonical_dir = octave::sys::canonicalize_file_name (dir); + if (! canonical_dir.empty ()) + dir = canonical_dir; + + if (! is_absolute_path) + { + // Remove current path from absolute path generated by + // canonicalize_file_name. + std::string cwd = octave::sys::canonicalize_file_name ("."); + if (dir.compare (0, cwd.length (), cwd) == 0) + dir.erase (0, cwd.length ()+1); + if (dir.empty ()) + dir = "."; + } + auto pos = dir.find_last_of (octave::sys::file_ops::dir_sep_chars ()); if (pos == std::string::npos) { if (! dir.empty () && dir[0] == '+') warning_with_id ("Octave:addpath-pkg", - "addpath: package directories should not be added to path: %s\n", dir.c_str ()); + "addpath: package directories should not be " + "added to path: %s\n", dir.c_str ()); } else { if (pos + 1 < dir.length () && dir[pos+1] == '+') warning_with_id ("Octave:addpath-pkg", - "addpath: package directories should not be added to path: %s\n", dir.c_str ()); + "addpath: package directories should not be " + "added to path: %s\n", dir.c_str ()); } if (append)