Dry run logging

This commit is contained in:
Darryl Nixon 2023-07-16 11:34:35 -07:00
parent 2b20dc6cc8
commit dacc4a89c7

View file

@ -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