Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
update refer logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Heavybullets8 committed May 29, 2024
1 parent 429bc38 commit 7c868e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
14 changes: 9 additions & 5 deletions functions/backup_restore/zfs/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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}")
12 changes: 8 additions & 4 deletions functions/backup_restore/zfs/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 7c868e9

Please sign in to comment.