From 20c6f79a4472c0986bed0409c841bfae2b66d1dc Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Sun, 5 Jul 2020 10:44:49 +0200 Subject: [PATCH] Changed behavior delete books with subfolders (additional warning message, but book is deleted) --- cps/helper.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cps/helper.py b/cps/helper.py index 48efc69b..20f3d4ad 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -295,15 +295,16 @@ def delete_book_file(book, calibrepath, book_format=None): return True, None else: if os.path.isdir(path): - if len(next(os.walk(path))[1]): - log.error("Deleting book %s failed, path has subfolders: %s", book.id, book.path) - return False , _("Deleting book %(id)s failed, path has subfolders: %(path)s", - id=book.id, - path=book.path) try: - for root, __, files in os.walk(path): + for root, folders, files in os.walk(path): for f in files: os.unlink(os.path.join(root, f)) + if len(folders): + log.warning("Deleting book {} failed, path {} has subfolders: {}".format(book.id, + book.path, folders)) + return True, _("Deleting bookfolder for book %(id)s failed, path has subfolders: %(path)s", + id=book.id, + path=book.path) shutil.rmtree(path) except (IOError, OSError) as e: log.error("Deleting book %s failed: %s", book.id, e)