From ebc396dc858727abed6bcb97ae1db49c33848073 Mon Sep 17 00:00:00 2001 From: Fallen_Breath Date: Tue, 22 Oct 2024 23:46:35 +0800 Subject: [PATCH] hide those BlobFileChanged warnings, unless it's the last chance keep it quiet --- prime_backup/action/create_backup_action.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/prime_backup/action/create_backup_action.py b/prime_backup/action/create_backup_action.py index b04892f..67575f1 100644 --- a/prime_backup/action/create_backup_action.py +++ b/prime_backup/action/create_backup_action.py @@ -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: @@ -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))