diff --git a/include/abg-tools-utils.h b/include/abg-tools-utils.h index c95c324c..36dbaf57 100644 --- a/include/abg-tools-utils.h +++ b/include/abg-tools-utils.h @@ -52,6 +52,7 @@ bool base_name(string const& path, bool dir_name(string const &path, string& path_dir_name, bool keep_separator_at_end=false); +void real_path(const string&path, string& realpath); bool ensure_dir_path_created(const string&); bool ensure_parent_dir_created(const string&); ostream& emit_prefix(const string& prog_name, ostream& out); diff --git a/src/abg-tools-utils.cc b/src/abg-tools-utils.cc index c448358f..63f52dc5 100644 --- a/src/abg-tools-utils.cc +++ b/src/abg-tools-utils.cc @@ -386,6 +386,28 @@ base_name(string const &path, return true; } +/// Return the real path of a given path. +/// +/// The real path of path 'foo_path' is the same path as foo_path, but +/// with symlinks and relative paths resolved. +/// +/// @param path the path to consider. +/// +/// @param result the computed real_path; +void +real_path(const string&path, string& result) +{ + if (path.empty()) + { + result.clear(); + return; + } + + char *realp = realpath(path.c_str(), NULL); + if (realp) + result = realp; +} + /// Ensures #dir_path is a directory and is created. If #dir_path is /// not created, this function creates it. /// diff --git a/tools/abipkgdiff.cc b/tools/abipkgdiff.cc index d0476d9a..ff809cf3 100644 --- a/tools/abipkgdiff.cc +++ b/tools/abipkgdiff.cc @@ -124,6 +124,7 @@ using abigail::tools_utils::ensure_dir_path_created; using abigail::tools_utils::guess_file_type; using abigail::tools_utils::string_ends_with; using abigail::tools_utils::dir_name; +using abigail::tools_utils::real_path; using abigail::tools_utils::string_suffix; using abigail::tools_utils::sorted_strings_common_prefix; using abigail::tools_utils::file_type; @@ -592,7 +593,13 @@ public: /// the extracted directory. bool convert_path_to_relative(const string& path, string& converted_path) const - {return string_suffix(path, extracted_dir_path(), converted_path);} + { + string root = extracted_dir_path_; + real_path(root, root); + string p = path; + real_path(p, p); + return string_suffix(p, root, converted_path); + } // Convert the absolute path of an element of this package into a // path relative to the prefix common to the paths of all elements @@ -1832,7 +1839,12 @@ get_interesting_files_under_dir(const string dir, vector& interesting_files) { bool is_ok = false; - char* paths[] = {const_cast(dir.c_str()), 0}; + string root; + real_path(dir, root); + if (root.empty()) + root = dir; + + char* paths[] = {const_cast(root.c_str()), 0}; FTS *file_hierarchy = fts_open(paths, FTS_LOGICAL|FTS_NOCHDIR, NULL); if (!file_hierarchy)