From 864baff1346b191512d89e5e1175cee73e0cc272 Mon Sep 17 00:00:00 2001 From: Filip Brygidyn Date: Sat, 9 Nov 2019 17:59:25 +0100 Subject: [PATCH] Walk Method: Do not erroneously ommit directories and top level files This fixes a bug of missing search results introduced in commit 5cd2f114 diff --git a/catfish/CatfishSearchEngine.py b/catfish/CatfishSearchEngine.py index d53f12c8..fa5b3b46 100644 --- a/catfish/CatfishSearchEngine.py +++ b/catfish/CatfishSearchEngine.py @@ -307,8 +307,9 @@ class CatfishSearchMethod_Walk(CatfishSearchMethod): notdotlinks = [] for path in dirs: path = os.path.join(root, path) - if not path.endswith("/"): - path = path + "/" + # Remove trailing slashes to ensure that calling os.path.basename() + # will not cut the path to an empty string + path = os.path.normpath(path) if path in exclude_list: continue if path in xdg_list: @@ -373,6 +374,19 @@ class CatfishSearchMethod_Walk(CatfishSearchMethod): ] for path in self.get_root_list(path, xdgdirlist, exclude): + + # Check if we've already processed symbolic paths + if os.path.islink(path): + realpath = os.path.realpath(path) + if realpath in processed_links: + yield True + continue + processed_links.append(realpath) + + # Check paths in the first level of the selected directory + if any(keyword in path.lower() for keyword in keywords): + yield path + for root, dirs, files in os.walk(top=path, topdown=True, onerror=None, followlinks=True): @@ -393,6 +407,8 @@ class CatfishSearchMethod_Walk(CatfishSearchMethod): paths = dirs + files paths.sort() + + # Check paths in the second and deeper levels of the selected directory for path in paths: if any(keyword in path.lower() for keyword in keywords): yield os.path.join(root, path) -- 2.24.0