From 970ca5293e19fef2e0a9d75e047e201aed5e2346 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 23 Apr 2023 20:59:31 +0530 Subject: [PATCH] Fix a regression in the previous release that could result in empty author folders remaining in the library when the author of a book is changed --- src/calibre/db/backend.py | 3 +++ src/calibre/db/tests/filesystem.py | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/calibre/db/backend.py b/src/calibre/db/backend.py index d9e92bde5a..a636d9d503 100644 --- a/src/calibre/db/backend.py +++ b/src/calibre/db/backend.py @@ -1872,6 +1872,9 @@ class DB: if os.path.exists(spath): copy_tree(os.path.abspath(spath), tpath, delete_source=True, transform_destination_filename=transform_format_filenames) + parent = os.path.dirname(spath) + with suppress(OSError): + os.rmdir(parent) # remove empty parent directory else: os.makedirs(tpath) update_paths_in_db() diff --git a/src/calibre/db/tests/filesystem.py b/src/calibre/db/tests/filesystem.py index 724994c053..db55ccac8d 100644 --- a/src/calibre/db/tests/filesystem.py +++ b/src/calibre/db/tests/filesystem.py @@ -127,7 +127,10 @@ class FilesystemTest(BaseTest): from calibre.ebooks.metadata.book.base import Metadata cache.set_metadata(1, Metadata('t1', ('a1', 'a2'))) check_that_filesystem_and_db_entries_match(1) - + # check that empty author folders are removed + for x in os.scandir(cache.backend.library_path): + if x.is_dir(): + self.assertTrue(os.listdir(x.path)) @unittest.skipUnless(iswindows, 'Windows only') def test_windows_atomic_move(self):