Skip to content

Commit

Permalink
hide those BlobFileChanged warnings, unless it's the last chance
Browse files Browse the repository at this point in the history
keep it quiet
  • Loading branch information
Fallen-Breath committed Oct 22, 2024
1 parent 7ee7cfd commit ebc396d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions prime_backup/action/create_backup_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,14 @@ def attempt_once(last_chance: bool = False) -> Generator[Any, Any, schema.Blob]:
# if any yield is done, ensure to check __blob_by_hash_cache again

def check_changes(new_size: int, new_hash: Optional[str]):
def log(s: str):
(self.logger.warning if last_chance else self.logger.debug)(s)

if new_size != st.st_size:
self.logger.warning('Blob size mismatch, previous: {}, current: {}'.format(st.st_size, new_size))
log('Blob size mismatch, previous: {}, current: {}'.format(st.st_size, new_size))
raise _BlobFileChanged()
if blob_hash is not None and new_hash is not None and new_hash != blob_hash:
self.logger.warning('Blob hash mismatch, previous: {}, current: {}'.format(blob_hash, new_hash))
log('Blob hash mismatch, previous: {}, current: {}'.format(blob_hash, new_hash))
raise _BlobFileChanged()

def bp_rba(h: str) -> Path:
Expand Down Expand Up @@ -493,8 +496,9 @@ def bp_rba(h: str) -> Path:
self.__blob_by_hash_cache[blob.hash] = blob
return blob, st
except _BlobFileChanged:
next_action = 'No more retry' if is_last_attempt else 'Retrying'
self.logger.warning('Blob {} stat has changed, has someone modified it? {} (attempt {} / {})'.format(src_path_str, next_action, retry_cnt, _BLOB_FILE_CHANGED_RETRY_COUNT))
(self.logger.warning if is_last_attempt else self.logger.debug)('Blob {} stat has changed, has someone modified it? {} (attempt {} / {})'.format(
src_path_str, 'No more retry' if is_last_attempt else 'Retrying', retry_cnt, _BLOB_FILE_CHANGED_RETRY_COUNT
))
st = src_path.lstat()
except Exception as e:
self.logger.error('Create blob for file {} failed (attempt {} / {}): {}'.format(src_path_str, e, retry_cnt, _BLOB_FILE_CHANGED_RETRY_COUNT))
Expand Down

0 comments on commit ebc396d

Please sign in to comment.