From dacc4a89c7f769f981ddd996727a64666bcc511c Mon Sep 17 00:00:00 2001 From: Darryl Nixon Date: Sun, 16 Jul 2023 11:34:35 -0700 Subject: [PATCH] Dry run logging --- melamine/classes.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/melamine/classes.py b/melamine/classes.py index 950232b..e6b62eb 100644 --- a/melamine/classes.py +++ b/melamine/classes.py @@ -104,39 +104,53 @@ class ShredFile(AsyncObject): logger.info(f"Got hash {sha1.hexdigest()}") # First pass: Overwrite with binary zeroes - logger.info(f"[1/4] Writing zeroes ({self.absolute_path.name})") + log_buf = f"[1/4] Writing zeroes ({self.absolute_path.name})" await file.seek(0) if not dryrun: await file.write(b"\x00" * self.byte_size) + else: + log_buf = "DRY RUN (no changes made) " + log_buf + logger.info(log_buf) await file.flush() # Second pass: Overwrite with binary ones - logger.info(f"[2/4] Writing ones ({self.absolute_path.name})") + log_buf = f"[2/4] Writing ones ({self.absolute_path.name})" await file.seek(0) if not dryrun: await file.write(b"\xff" * self.byte_size) + else: + log_buf = "DRY RUN (no changes made) " + log_buf + logger.info(log_buf) await file.flush() # Third pass: Overwrite with random data - logger.info(f"[3/4] Writing randoms ({self.absolute_path.name})") + log_buf = f"[3/4] Writing randoms ({self.absolute_path.name})" await file.seek(0) random_data = token_bytes(self.byte_size) if not dryrun: await file.write(random_data) + else: + log_buf = "DRY RUN (no changes made) " + log_buf + logger.info(log_buf) await file.flush() # Remove the file - logger.info(f"[4/4] Unlinking {self.absolute_path}") - + log_buf = f"[4/4] Unlinking {self.absolute_path}" if not dryrun: await file.unlink() + else: + log_buf = "DRY RUN (no changes made) " + log_buf + logger.info(log_buf) # Remove any hardlinks if self.hardlinks: - logger.info(f"[5/4] Unlinking {len(self.hardlinks)} hardlinks") + log_buf = f"[5/4] Unlinking {len(self.hardlinks)} hardlinks" if not dryrun: for link in self.hardlinks: await link.unlink() + else: + log_buf = "DRY RUN (no changes made) " + log_buf + logger.info(log_buf) return True