From 50e583f2c2d2714460e6083dd58bf2fe1702ffae Mon Sep 17 00:00:00 2001
From: "Antoine R. Dumont (@ardumont)" <antoine.romain.dumont@gmail.com>
Date: Mon, 17 Sep 2018 10:58:11 +0200
Subject: [PATCH] MultiHash.from_path: Use the length coming from os.path

---
 swh/model/hashutil.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/swh/model/hashutil.py b/swh/model/hashutil.py
index df73142a..0e789834 100644
--- a/swh/model/hashutil.py
+++ b/swh/model/hashutil.py
@@ -95,11 +95,12 @@ class MultiHash:
                   track_length=True):
         if not length:
             length = os.path.getsize(path)
+        with open(path, 'rb') as f:
+            ret = cls.from_file(f, hash_names=hash_names, length=length)
         # For compatibility reason with `hash_path`
         if track_length:
-            hash_names = hash_names.union(EXTRA_LENGTH)
-        with open(path, 'rb') as f:
-            return cls.from_file(f, hash_names=hash_names, length=length)
+            ret.state['length'] = length
+        return ret
 
     @classmethod
     def from_data(cls, data, hash_names=DEFAULT_ALGORITHMS, length=None):
-- 
GitLab