Skip to content

Commit

Permalink
Fixed bad type in the blob object creation in FileInfo.of
Browse files Browse the repository at this point in the history
  • Loading branch information
Fallen-Breath committed Jul 21, 2024
1 parent c349e36 commit 5869cf1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
3 changes: 3 additions & 0 deletions prime_backup/action/validate_blobs_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}'))
Expand Down
3 changes: 3 additions & 0 deletions prime_backup/compressors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
20 changes: 12 additions & 8 deletions prime_backup/types/file_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 5869cf1

Please sign in to comment.