db67c021a0d9

Switch to basename matching, and implement --[no-]binary.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sat, 22 Sep 2012 16:50:23 -0400
parents d6c518c8ab39
children 8de084a9b64d
branches/tags (none)
files ffind

Changes

--- a/ffind	Sat Sep 22 15:54:17 2012 -0400
+++ b/ffind	Sat Sep 22 16:50:23 2012 -0400
@@ -78,16 +78,26 @@
 
     return False
 
-def match(query, path):
+def match(query, path, basename):
     def _match():
         if options.type != TYPES_ALL:
             if get_type(path) not in options.type:
                 return False
 
         if options.case == CASE_INSENSITIVE:
-            return query.lower() in path.lower()
+            if query.lower() not in basename.lower():
+                return False
         else:
-            return query in path
+            if query not in basename:
+                return False
+
+        if not options.binary:
+            with open(path) as f:
+                if '\0' in f.read(1024):
+                    return False
+
+        return True
+
 
     result = _match()
     return not result if options.invert else result
@@ -99,12 +109,14 @@
     for item in contents:
         path = os.path.join(dir, item)
         if not should_ignore(item, path):
-            if match(query, path):
+            if match(query, path, item):
                 out(path, '\0' if options.zero else '\n')
 
             is_dir = os.path.isdir(path)
             if is_dir:
-                next.append(path)
+                if options.follow or not os.path.islink(path):
+                    next.append(path)
+
 
     if depth < options.depth:
         for d in next: