diff --git a/prime_backup/action/validate_blobs_action.py b/prime_backup/action/validate_blobs_action.py index a1dd43b..8ac6ba8 100644 --- a/prime_backup/action/validate_blobs_action.py +++ b/prime_backup/action/validate_blobs_action.py @@ -47,6 +47,9 @@ def validate_one_blob(blob: BlobInfo): return try: + # Notes: There are some codes that use `CompressMethod[blob.compress]`, + # which might fail hard if the blob.compress is invalid. + # Maybe we need to make them fail-proof somehow? compressor = Compressor.create(blob.compress) except ValueError: result.invalid.append(BadBlobItem(blob, f'unknown compress method {blob.compress!r}')) diff --git a/prime_backup/compressors.py b/prime_backup/compressors.py index b3a861b..bb113d7 100644 --- a/prime_backup/compressors.py +++ b/prime_backup/compressors.py @@ -198,3 +198,6 @@ class CompressMethod(enum.Enum): lzma = LzmaCompressor zstd = ZstdCompressor lz4 = Lz4Compressor + + def __repr__(self) -> str: + return '{}({!r})'.format(self.__class__.__name__, self.name) diff --git a/prime_backup/types/file_info.py b/prime_backup/types/file_info.py index 868be3d..4516c61 100644 --- a/prime_backup/types/file_info.py +++ b/prime_backup/types/file_info.py @@ -4,6 +4,7 @@ import stat from typing import Optional +from prime_backup.compressors import CompressMethod from prime_backup.db import schema from prime_backup.types.blob_info import BlobInfo @@ -35,15 +36,18 @@ def of(cls, file: schema.File) -> 'FileInfo': """ Notes: should be inside a session """ + blob: Optional[BlobInfo] = None if file.blob_hash is not None: - blob = BlobInfo( - hash=str(file.blob_hash), - compress=file.blob_compress, - raw_size=file.blob_raw_size, - stored_size=file.blob_stored_size, - ) - else: - blob = None + if file.blob_compress not in CompressMethod.__members__: + from prime_backup import logger + logger.get().warning('Bad blob_compress {!r} for file {!r}'.format(file.blob_compress, file)) + else: + blob = BlobInfo( + hash=str(file.blob_hash), + compress=CompressMethod[file.blob_compress], + raw_size=file.blob_raw_size, + stored_size=file.blob_stored_size, + ) return FileInfo( backup_id=file.backup_id, path=file.path,