From fed22d3ab917f22e12ef90b9bed22491bd52c0b3 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Sat, 14 Apr 2018 08:14:13 +0300 Subject: [PATCH] utils: use dict_md5 Signed-off-by: Ruslan Kuprieiev --- dvc/state.py | 6 ++---- dvc/utils.py | 6 ++++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/dvc/state.py b/dvc/state.py index 13e54d9bb..4d32bc1d6 100644 --- a/dvc/state.py +++ b/dvc/state.py @@ -5,7 +5,7 @@ import threading from dvc.system import System from dvc.output import Output -from dvc.utils import file_md5, bytes_md5 +from dvc.utils import file_md5, dict_md5 from dvc.exceptions import DvcException @@ -70,9 +70,7 @@ class State(object): def compute_md5(self, path): if os.path.isdir(path): dir_info = self.collect_dir(path) - byts = json.dumps(dir_info, sort_keys=True).encode('utf-8') - md5 = bytes_md5(byts) - return md5 + Output.MD5_DIR_SUFFIX + return dict_md5(dir_info) + Output.MD5_DIR_SUFFIX else: return file_md5(path)[0] diff --git a/dvc/utils.py b/dvc/utils.py index b3196dac5..ef4d63f75 100644 --- a/dvc/utils.py +++ b/dvc/utils.py @@ -3,6 +3,7 @@ Helpers for other modules. """ import os import re +import json import stat import shutil import hashlib @@ -34,6 +35,11 @@ def bytes_md5(byts): return hasher.hexdigest() +def dict_md5(d): + byts = json.dumps(d, sort_keys=True).encode('utf-8') + return bytes_md5(byts) + + def cached_property(func): '''A decorator for caching properties in classes.''' def get(self):