This commit is contained in:
Łukasz Langa 2016-10-29 19:27:18 -07:00
parent 5e66b772d2
commit d192fa0175
2 changed files with 7 additions and 3 deletions

View File

@ -44,6 +44,8 @@ Change Log
* bugfix: when using -q, don't hide warnings about files that can't be * bugfix: when using -q, don't hide warnings about files that can't be
statted or read statted or read
* bugfix: -s is no longer broken on Python 3
0.9.0 0.9.0
~~~~~ ~~~~~

View File

@ -42,7 +42,7 @@ import time
DEFAULT_CHUNK_SIZE = 16384 DEFAULT_CHUNK_SIZE = 16384
DOT_THRESHOLD = 200 DOT_THRESHOLD = 200
VERSION = (0, 9, 0) VERSION = (0, 9, 1)
IGNORED_FILE_SYSTEM_ERRORS = {errno.ENOENT, errno.EACCES} IGNORED_FILE_SYSTEM_ERRORS = {errno.ENOENT, errno.EACCES}
FSENCODING = sys.getfilesystemencoding() FSENCODING = sys.getfilesystemencoding()
@ -382,18 +382,20 @@ def get_path(directory=b'.', ext=b'db'):
return os.path.join(directory, b'.bitrot.' + ext) return os.path.join(directory, b'.bitrot.' + ext)
def stable_sum(bitrot_db): def stable_sum(bitrot_db=None):
"""Calculates a stable SHA512 of all entries in the database. """Calculates a stable SHA512 of all entries in the database.
Useful for comparing if two directories hold the same data, as it ignores Useful for comparing if two directories hold the same data, as it ignores
timing information.""" timing information."""
if bitrot_db is None:
bitrot_db = get_path()
digest = hashlib.sha512() digest = hashlib.sha512()
conn = get_sqlite3_cursor(bitrot_db) conn = get_sqlite3_cursor(bitrot_db)
cur = conn.cursor() cur = conn.cursor()
cur.execute('SELECT hash FROM bitrot ORDER BY path') cur.execute('SELECT hash FROM bitrot ORDER BY path')
row = cur.fetchone() row = cur.fetchone()
while row: while row:
digest.update(row[0]) digest.update(row[0].encode('ascii'))
row = cur.fetchone() row = cur.fetchone()
return digest.hexdigest() return digest.hexdigest()