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

This commit is contained in:
Kovid Goyal 2023-04-23 20:59:31 +05:30
parent 4bb9c9fba8
commit 970ca5293e
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 7 additions and 1 deletions

View File

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

View File

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