diff --git a/functions/backup_restore/zfs/cache.py b/functions/backup_restore/zfs/cache.py index 0c5151e..7a14f28 100644 --- a/functions/backup_restore/zfs/cache.py +++ b/functions/backup_restore/zfs/cache.py @@ -72,10 +72,14 @@ def _load_snapshots(self) -> dict: def _convert_size_to_bytes(self, size_str): size_units = {"K": 1024, "M": 1024**2, "G": 1024**3, "T": 1024**4} - if size_str[-1] in size_units: - return int(float(size_str[:-1]) * size_units[size_str[-1]]) - else: - return int(size_str) + try: + if size_str[-1] in size_units: + return int(float(size_str[:-1]) * size_units[size_str[-1]]) + else: + return int(size_str) + except ValueError: + self.logger.error(f"Invalid size string: {size_str}") + return 0 def hard_refresh(self): """ @@ -189,4 +193,4 @@ def remove_snapshot(self, snapshot: str): with self._lock: if snapshot in ZFSCache._snapshots: del ZFSCache._snapshots[snapshot] - self.logger.debug(f"Removed snapshot: {snapshot}") + self.logger.debug(f"Removed snapshot: {snapshot}") \ No newline at end of file diff --git a/functions/backup_restore/zfs/snapshot.py b/functions/backup_restore/zfs/snapshot.py index a9b9320..f8f354b 100644 --- a/functions/backup_restore/zfs/snapshot.py +++ b/functions/backup_restore/zfs/snapshot.py @@ -83,10 +83,14 @@ def get_snapshot_refer_size(self, snapshot: str) -> int: @type_check def _convert_size_to_bytes(self, size_str): size_units = {"K": 1024, "M": 1024**2, "G": 1024**3, "T": 1024**4} - if size_str[-1] in size_units: - return int(float(size_str[:-1]) * size_units[size_str[-1]]) - else: - return int(size_str) + try: + if size_str[-1] in size_units: + return int(float(size_str[:-1]) * size_units[size_str[-1]]) + else: + return int(size_str) + except ValueError: + self.logger.error(f"Invalid size string: {size_str}") + return 0 @type_check def delete_snapshot(self, snapshot: str) -> dict: