From 07f3b44e2904c47074f0943a89efc612febc9805 Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Mon, 5 Nov 2012 22:21:22 +0000 Subject: [PATCH] use one catkin_find invocation instead of multiple to achieve correct workspace overlaying, keep order in uniquified result list --- core/roslib/src/roslib/packages.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/core/roslib/src/roslib/packages.py b/core/roslib/src/roslib/packages.py index b277207a..2e492f5a 100644 --- a/core/roslib/src/roslib/packages.py +++ b/core/roslib/src/roslib/packages.py @@ -494,13 +494,15 @@ def find_resource(pkg, resource_name, filter_fn=None, rospack=None): # if found in binary dir, start with that. in any case, use matches # from ros_package_path matches = [] - for search_dirs in ['libexec', 'share']: - try: - search_paths = catkin_find(search_dirs=[search_dirs], project=pkg) - for search_path in search_paths: - matches.extend(_find_resource(search_path, resource_name, filter_fn=filter_fn)) - except RuntimeError: - pass + search_paths = catkin_find(search_dirs=['libexec', 'share'], project=pkg, first_matching_workspace_only=True) + for search_path in search_paths: + matches.extend(_find_resource(search_path, resource_name, filter_fn=filter_fn)) + matches.extend(_find_resource(pkg_path, resource_name, filter_fn=filter_fn)) - # Uniquify the results, in case we found the same file twice - return list(set(matches)) + + # Uniquify the results, in case we found the same file twice, while keeping order + unique_matches = [] + for match in matches: + if match not in unique_matches: + unique_matches.append(match) + return unique_matches