Skip to content

Commit

Permalink
Fix bug with forced rechecking
Browse files Browse the repository at this point in the history
Forced rechecking caused older cached files that had been deleted to not
be pruned from the cache. Forcing a recheck now completely flushes the
cache.
  • Loading branch information
jackstanek committed Jul 27, 2016
1 parent 9d8ba18 commit 49b1dad
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 20 deletions.
9 changes: 7 additions & 2 deletions botbot/botbot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Main method"""
import os
import sys

from botbot import __version__
Expand Down Expand Up @@ -82,8 +83,12 @@ def main():
all_file_checks = checks.ALLCHECKS + schecks.ALLSCHECKS
chkr.register(*all_file_checks)

chkr.check_all(path, shared=args.shared, link=args.follow_symlinks,
verbose=args.verbose, force=args.force_recheck)
chkr.check_all(path, shared=args.shared,
link=args.follow_symlinks,
verbose=args.verbose,
force=args.force_recheck,
me=args.me,
)

elif args.cmd == 'daemon':
pass
Expand Down
4 changes: 4 additions & 0 deletions botbot/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ def build_new_checklist(self, path, link=False, verbose=True, uid=None):
"""
Build a list of files to check. If link is True, follow symlinks.
"""

# Try to clear out the FileInfo cache
self.db.clear()

self.path = path
to_add = [path] # Acts like a stack, this does

Expand Down
49 changes: 31 additions & 18 deletions botbot/sqlcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,10 @@ def __init__(self, dbpath):
self.conn = sqlite3.connect(dbpath)
self.conn.row_factory = sqlite3.Row
self.curs = self.conn.cursor()

try:
# Create the file table
self.curs.execute(
'create table files\
(path text primary key,\
mode integer,\
uid integer,\
username text,\
size integer,\
lastmod float,\
lastcheck float,\
isfile integer,\
isdir integer,\
important integer,\
md5sum text,\
problems text)' # Problems are stored in the
# database# as comma-separated
# problem identifier strings. yee
)
self._create_table()

except sqlite3.OperationalError:
# Table already exists, ya goof
pass
Expand All @@ -77,6 +62,26 @@ def _prep_fileinfos(self, rows):

return files

def _create_table(self):
# Create the file table
self.curs.execute(
'create table files\
(path text primary key,\
mode integer,\
uid integer,\
username text,\
size integer,\
lastmod float,\
lastcheck float,\
isfile integer,\
isdir integer,\
important integer,\
md5sum text,\
problems text)' # Problems are stored in the
# database# as comma-separated
# problem identifier strings. yee
)

def store_file_problems(self, *checked):
"""Store a list of FileInfos with their problems in the database"""

Expand Down Expand Up @@ -178,6 +183,14 @@ def prune(self, *old):
(f,)
)

def clear(self):
try:
self.curs.execute('drop table files')
self._create_table()

except sqlite3.OperationalError:
pass

def __del__(self):
"""Close everything before ya die"""
self.conn.commit()
Expand Down

0 comments on commit 49b1dad

Please sign in to comment.