Skip to content

Commit

Permalink
Factor out old/large file detection
Browse files Browse the repository at this point in the history
  • Loading branch information
jackstanek committed Jul 22, 2016
1 parent 4bac0cf commit df6c94a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions botbot/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,17 @@ def is_large_plaintext(fi):
"""Detect if a file plaintext and >100MB"""
# Try to figure out if we're dealing with a text file
guess = mimetypes.guess_type(fi['path'])[0]
if guess == 'text/plain' and is_old_and_large(fi):
return 'PROB_OLD_LARGE_PLAINTEXT'

def is_old_and_large(fi):
mod_days = int(time.time() - fi['lastmod'] / (24 * 60 * 60))
# Days since last modification

large = CONFIG.get('checks', 'largesize',
fallback=100000000) # Default to 100MB
old = CONFIG.get('checks', 'oldage',
fallback=30) # Default to one month
if guess == 'text/plain' and fi['size'] > int(large) and mod_days >= int(old):
return 'PROB_OLD_LARGE_PLAINTEXT'

if fi['size'] > int(large) and mod_days >= int(old):
return 'PROB_OLD_LARGE'

0 comments on commit df6c94a

Please sign in to comment.