Correct file search implementation

The behavior for searching "file" more closely matches the documented
behavior for "path".  Implement "path" the same as "file", then update
"file" so that the non-regex form matches path components.

Change-Id: I03bf6d5232472069ea288b1ce0fe955469791af1
This commit is contained in:
James E. Blair 2019-07-29 16:08:22 -07:00
parent 6b794c03ee
commit 9105cbb232
2 changed files with 14 additions and 0 deletions

View File

@ -95,6 +95,7 @@ def SearchParser():
| is_term | is_term
| status_term | status_term
| file_term | file_term
| path_term
| limit_term | limit_term
| op_term''' | op_term'''
p[0] = p[1] p[0] = p[1]
@ -318,6 +319,18 @@ def SearchParser():
def p_file_term(p): def p_file_term(p):
'''file_term : OP_FILE string''' '''file_term : OP_FILE string'''
if p[2].startswith('^'):
p[0] = and_(or_(func.matches(p[2], gertty.db.file_table.c.path),
func.matches(p[2], gertty.db.file_table.c.old_path)),
gertty.db.file_table.c.status is not None)
else:
file_re = '(^|.*/)%s(/.*|$)' % re.escape(p[2])
p[0] = and_(or_(func.matches(file_re, gertty.db.file_table.c.path),
func.matches(file_re, gertty.db.file_table.c.old_path)),
gertty.db.file_table.c.status is not None)
def p_path_term(p):
'''path_term : OP_PATH string'''
if p[2].startswith('^'): if p[2].startswith('^'):
p[0] = and_(or_(func.matches(p[2], gertty.db.file_table.c.path), p[0] = and_(or_(func.matches(p[2], gertty.db.file_table.c.path),
func.matches(p[2], gertty.db.file_table.c.old_path)), func.matches(p[2], gertty.db.file_table.c.old_path)),

View File

@ -36,6 +36,7 @@ operators = {
'message': 'OP_MESSAGE', 'message': 'OP_MESSAGE',
'comment': 'OP_COMMENT', 'comment': 'OP_COMMENT',
'file': 'OP_FILE', 'file': 'OP_FILE',
'path': 'OP_PATH',
'has': 'OP_HAS', 'has': 'OP_HAS',
'is': 'OP_IS', 'is': 'OP_IS',
'status': 'OP_STATUS', 'status': 'OP_STATUS',