diff --git a/swh/storage/fixer.py b/swh/storage/fixer.py --- a/swh/storage/fixer.py +++ b/swh/storage/fixer.py @@ -8,8 +8,7 @@ import logging from typing import Any, Dict, List, Optional -from swh.model.identifiers import normalize_timestamp -from swh.model.model import Origin +from swh.model.model import Origin, TimestampWithTimezone logger = logging.getLogger(__name__) @@ -70,12 +69,12 @@ """ if date is None: return True - date = normalize_timestamp(date) - return ( - (-(2 ** 63) <= date["timestamp"]["seconds"] < 2 ** 63) - and (0 <= date["timestamp"]["microseconds"] < 10 ** 6) - and (-(2 ** 15) <= date["offset"] < 2 ** 15) - ) + try: + TimestampWithTimezone.from_dict(date) + except ValueError: + return False + else: + return True def _check_revision_date(rev): diff --git a/swh/storage/tests/algos/test_diff.py b/swh/storage/tests/algos/test_diff.py --- a/swh/storage/tests/algos/test_diff.py +++ b/swh/storage/tests/algos/test_diff.py @@ -11,7 +11,6 @@ import pytest from swh.model.hashutil import hash_to_bytes -from swh.model.identifiers import directory_identifier from swh.storage.algos import diff from .test_dir_iterator import DirectoryModel diff --git a/swh/storage/tests/algos/test_dir_iterator.py b/swh/storage/tests/algos/test_dir_iterator.py --- a/swh/storage/tests/algos/test_dir_iterator.py +++ b/swh/storage/tests/algos/test_dir_iterator.py @@ -8,7 +8,7 @@ from swh.model.from_disk import DentryPerms from swh.model.hashutil import MultiHash, hash_to_bytes -from swh.model.identifiers import directory_identifier +from swh.model.model import Directory from swh.storage.algos.dir_iterators import dir_iterator # flake8: noqa @@ -30,7 +30,19 @@ def __getitem__(self, item): if item == "target": - return hash_to_bytes(directory_identifier(self)) + return Directory.from_dict( + { + "entries": [ + { + "name": entry["name"], + "target": entry["target"], + "type": entry["type"], + "perms": entry["perms"], + } + for entry in self.data["entries"] + ] + } + ).id else: return self.data[item]