diff --git a/swh/model/from_disk.py b/swh/model/from_disk.py index a9fc2d3be52ef0869c1eea2a10497bde02d775dd..bfd7c7cd026f271be37aecca9d2435b683304403 100644 --- a/swh/model/from_disk.py +++ b/swh/model/from_disk.py @@ -77,9 +77,8 @@ class Content(MerkleLeaf): mode (int): a file mode (passed to :func:`mode_to_perms`) data (bytes): raw contents of the file """ - length = len(data) - ret = MultiHash.from_data(data, length=length).digest() - ret['length'] = length + ret = MultiHash.from_data(data).digest() + ret['length'] = len(data) ret['perms'] = mode_to_perms(mode) ret['data'] = data diff --git a/swh/model/hashutil.py b/swh/model/hashutil.py index 24c2f6961f8039572632367b84363c9b4478d367..91250f4f5b9f04129c2a3a8ebf8e6bdac2aa7134 100644 --- a/swh/model/hashutil.py +++ b/swh/model/hashutil.py @@ -127,21 +127,15 @@ class MultiHash: return ret @classmethod - def from_path(cls, path, hash_names=DEFAULT_ALGORITHMS, length=None, - track_length=True): - if not length: - length = os.path.getsize(path) + def from_path(cls, path, hash_names=DEFAULT_ALGORITHMS): + 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: - ret.state['length'] = length return ret @classmethod - def from_data(cls, data, hash_names=DEFAULT_ALGORITHMS, length=None): - if not length: - length = len(data) + def from_data(cls, data, hash_names=DEFAULT_ALGORITHMS): + length = len(data) fobj = BytesIO(data) return cls.from_file(fobj, hash_names=hash_names, length=length) diff --git a/swh/model/tests/test_hashutil.py b/swh/model/tests/test_hashutil.py index 92b3684afe807774a9b8ed315bf1e39095b5e225..94a66ddc1df43b2c3f9de69584b925a87f4cb476 100644 --- a/swh/model/tests/test_hashutil.py +++ b/swh/model/tests/test_hashutil.py @@ -117,7 +117,6 @@ class MultiHashTest(BaseHashutil): hashes = MultiHash.from_path(f.name).digest() os.remove(f.name) - self.checksums['length'] = len(self.data) self.assertEquals(self.checksums, hashes)