From 55652662ca75cc062235f00f6ade2904f06ad132 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Thu, 20 Apr 2023 09:53:41 +0200 Subject: [PATCH] Fix deleted file calculation We stupidly just output the total number of files, and not the number of files that we attempted to delete, which leads to flawed statistics output. --- cleanmedia | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cleanmedia b/cleanmedia index 3fc404c..47c2fd9 100755 --- a/cleanmedia +++ b/cleanmedia @@ -187,10 +187,11 @@ if __name__ == '__main__': #------------------ cleantime = datetime.today() - timedelta(days=args.days) logging.info("Deleting remote media older than %s", cleantime) + num_deleted = 0 files = mr.get_remote_media() for file in files: if file.create_date < cleantime: - num_deleted = 0 + num_deleted += 1 if args.dryrun: # the great pretender logging.info(f"Pretending to delete file id {file.media_id} on path {file.fullpath}.") if not file.exists(): @@ -198,6 +199,6 @@ if __name__ == '__main__': else: file.delete() if args.dryrun: - logging.info("%d files would have been deleted during the run.",len(files)) + logging.info("%d files would have been deleted during the run.", num_deleted) else: - logging.info("Deleted %d files during the run.",len(files)) + logging.info("Deleted %d files during the run.", num_deleted)