Skip to content

Commit

Permalink
chg: [hashlookup] if a file cannot be read (e.g. Permission denied) for
Browse files Browse the repository at this point in the history
hashing

Those are skipped, accounted in the nonanalysed files.
  • Loading branch information
adulau committed Dec 28, 2021
1 parent 6450394 commit d408eba
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions bin/hashlookup-analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,24 @@ def lookup(value=None):
continue

sha1 = hashlib.sha1()
with open(fn, 'rb') as f:
try:
size = os.fstat(f.fileno()).st_size
except:
size = 0
pass
while True:
data = f.read(BUF_SIZE)
if not data:
break
sha1.update(data)
h = sha1.hexdigest().upper()
try:
with open(fn, 'rb') as f:
try:
size = os.fstat(f.fileno()).st_size
except:
size = 0
pass
while True:
data = f.read(BUF_SIZE)
if not data:
break
sha1.update(data)
h = sha1.hexdigest().upper()
except Exception as e:
sys.stderr.write(f'Unable to read {e} file {fn}\n')
notanalysed_files.append(f'{fn},{e}')
stats['excluded'] += 1
pass

knowncachefile = f'{CACHE_DIR}/known/{h}'
cachefile = f'{CACHE_DIR}/unknown/{h}'
Expand Down

0 comments on commit d408eba

Please sign in to comment.