[Xfce4-commits] [apps/catfish] 01/03: Walk Method: Do not erroneously ommit directories and top level files

noreply at xfce.org noreply at xfce.org
Thu Dec 19 11:45:08 CET 2019


This is an automated email from the git hooks/post-receive script.

b   l   u   e   s   a   b   r   e       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository apps/catfish.

commit f7f0aa648b8b75d096f1505a392ab6038a538be6
Author: Filip Brygidyn <git at koumakan.org>
Date:   Sat Nov 9 17:59:25 2019 +0100

    Walk Method: Do not erroneously ommit directories and top level files
    
    This fixes a bug of missing search results introduced in commit 5cd2f114
    
    Signed-off-by: Sean Davis <smd.seandavis at gmail.com>
---
 catfish/CatfishSearchEngine.py | 45 +++++++++++++++++++++++++++++++++---------
 1 file changed, 36 insertions(+), 9 deletions(-)

diff --git a/catfish/CatfishSearchEngine.py b/catfish/CatfishSearchEngine.py
index d53f12c..64b60ea 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:
@@ -330,15 +331,26 @@ class CatfishSearchMethod_Walk(CatfishSearchMethod):
         return dirlist
 
     def get_root_list(self, path, xdg_list, exclude_list):
-        # Sort the roots alphabetically
-        roots = [d for d in os.listdir(path)
-                 if os.path.isdir(os.path.join(path, d)) and
-                 os.path.join(path, d) not in exclude_list]
-        roots = sorted(roots, key=lambda s: s.lower())
+        root_dirs = []
+        root_files = []
+        for d in os.listdir(path):
+            if os.path.join(path, d) not in exclude_list:
+                if os.path.isdir(os.path.join(path, d)):
+                    root_dirs.append(d)
+                else:
+                    root_files.append(os.path.join(path, d))
+
         results = []
-        for dirpath in self.get_dir_list(path, roots, xdg_list, exclude_list):
+        for dirpath in self.get_dir_list(path, root_dirs, xdg_list, exclude_list):
             results.append(os.path.join(path, dirpath))
-        return results
+
+        # Sort the root files alphabetically
+        # root dirs were already sorted in get_dir_list()
+        root_files = sorted(root_files, key=lambda s: s.lower())
+
+        # Return files first to be displayed right away
+        # and then priortized dir paths that will be traversed
+        return root_files + results
 
     def run(self, keywords, path, regex=False, exclude_paths=[]):
         """Run the search method using keywords and path.  regex is not used
@@ -373,6 +385,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 +418,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)

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list