# HG changeset patch # User Steve Losh # Date 1348347023 14400 # Node ID db67c021a0d9576716eb9cdd78c78f4a503d2705 # Parent d6c518c8ab395fda08ad3d3aa3661504b95d8f5a Switch to basename matching, and implement --[no-]binary. diff -r d6c518c8ab39 -r db67c021a0d9 ffind --- 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: