diff --git a/src/log_setup/rotation.py b/src/log_setup/rotation.py index 4967256..96b7def 100644 --- a/src/log_setup/rotation.py +++ b/src/log_setup/rotation.py @@ -288,8 +288,14 @@ def retier(log_dir: str, stem: str, keep_uncompressed: int, keep_compressed: int files.sort(key=lambda t: (t[1], t[2]), reverse=True) keep = keep_uncompressed + keep_compressed + present = {p for p, _, _ in files} for index, (path, _, _) in enumerate(files): if index >= keep: + # never delete an intact plain whose only surviving twin is a CORRUPT .gz - + # that would leave the corrupt archive as the sole copy (data loss). keep the + # plain; a later retier retires it once a clean .gz exists. + if not path.endswith(".gz") and (path + ".gz") in present and not _gz_intact(path + ".gz"): + continue try: os.remove(path) except OSError: