From 7b6ecf25ac4af41ffd0a5beab2d9434995d6ee07 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Thu, 12 Jan 2023 14:53:32 +0100 Subject: [PATCH] reintroduce correct failure handling --- cleanmedia | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cleanmedia b/cleanmedia index 64d467f..3ad2a2a 100755 --- a/cleanmedia +++ b/cleanmedia @@ -59,15 +59,15 @@ class File: if self.fullpath is None: logging.info(f"No known path for file id '{self.media_id}', cannot delete file.") res = False - if not self.fullpath.is_dir(): + elif not self.fullpath.is_dir(): logging.debug(f"Path for file id '{self.media_id}' is not a directory or does not exist, not deleting.") res = False - - for file in self.fullpath.glob('*'): - # note: this does not handle directories in fullpath - file.unlink() - self.fullpath.rmdir() - logging.debug(f"Deleted directory {self.fullpath}") + else: + for file in self.fullpath.glob('*'): + # note: this does not handle directories in fullpath + file.unlink() + self.fullpath.rmdir() + logging.debug(f"Deleted directory {self.fullpath}") with self.repo.conn.cursor() as cur: cur.execute("DELETE from mediaapi_thumbnail WHERE media_id=%s;", (self.media_id,))