From 169da3ffed07ddb480f4e244d2611e96dad95dff Mon Sep 17 00:00:00 2001 From: Christopher Usher Date: Mon, 30 Sep 2019 02:45:29 +0100 Subject: [PATCH] started on checking the hash --- backfiller/backfiller/main.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backfiller/backfiller/main.py b/backfiller/backfiller/main.py index f2a23f1..d1ee678 100644 --- a/backfiller/backfiller/main.py +++ b/backfiller/backfiller/main.py @@ -2,6 +2,7 @@ import datetime import errno +import hashlib import logging import os import random @@ -9,6 +10,7 @@ import signal import socket import urlparse import uuid +from base64 import b64encode import argh import gevent.backdoor @@ -88,6 +90,8 @@ def get_remote_segment(base_dir, node, channel, quality, hour, missing_segment, temp_path = os.path.join(dir_name, "{}.ts".format(temp_name)) common.ensure_directory(temp_path) + hash = hashlib.sha256() + try: logging.debug('Fetching segment {} from {}'.format(path, node)) uri = '{}/segments/{}/{}/{}/{}'.format(node, channel, quality, hour, missing_segment) @@ -98,6 +102,10 @@ def get_remote_segment(base_dir, node, channel, quality, hour, missing_segment, with open(temp_path, 'w') as f: for chunk in resp.iter_content(8192): f.write(chunk) + hash.update(chunk) + + hash_str = b64encode(hash.digest(), "-_").rstrip("=") + logger.info('{} {}'.format(missing_segment, hash_str)) #try to get rid of the temp file if an exception is raised. except Exception: