# HG changeset patch # User Markus Mützel # Date 1570624503 -7200 # Node ID 5a0543de1e47a0bfb62ab8581111c92ea20df86c # Parent def608acdfa93d2bdf931cc20167300a82d47d32 Add canonical path when using addpath (bug #56267). * load-path.cc (Faddpath): Canonicalize path before adding it to the search path. diff -r def608acdfa9 -r 5a0543de1e47 libinterp/corefcn/load-path.cc --- 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)