Skip to content

Commit

Permalink
Only compute xxhash if .zst database has checksum
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronkollasch committed Mar 12, 2023
1 parent e33b835 commit 889857e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/photomanager/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,11 @@ def from_file(cls: Type[DB], path: Union[str, PathLike], create_new=False) -> DB
)
s = zstd.decompress(c)
del c
s_hash = xxhash.xxh64_digest(s)
if has_checksum and checksum != s_hash[-4:][::-1]:
if (
has_checksum
and (s_hash := xxhash.xxh64_digest(s))
and checksum != s_hash[-4:][::-1]
):
raise DatabaseException(
f"zstd content checksum verification failed: "
f"{checksum.hex()} != {s_hash.hex()}"
Expand All @@ -280,7 +283,7 @@ def to_file(self, path: Union[str, PathLike], overwrite: bool = False) -> None:
:param path: the destination path
:param overwrite: if false, do not overwrite an existing database at `path`
and instead rename the it based on its last modified timestamp.
and instead rename it based on its last modified timestamp.
"""
logger = logging.getLogger(__name__)
logger.debug(f"Saving database to {path}")
Expand Down

0 comments on commit 889857e

Please sign in to comment.