mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
When renaming authors fix empty author folder not being removed if it contained file explorer metadata but was otherwise empty
This commit is contained in:
parent
803c684049
commit
becebc1c0e
@ -1997,7 +1997,7 @@ class DB:
|
|||||||
copy_tree(os.path.abspath(spath), tpath, delete_source=True, transform_destination_filename=transform_format_filenames)
|
copy_tree(os.path.abspath(spath), tpath, delete_source=True, transform_destination_filename=transform_format_filenames)
|
||||||
parent = os.path.dirname(spath)
|
parent = os.path.dirname(spath)
|
||||||
with suppress(OSError):
|
with suppress(OSError):
|
||||||
os.rmdir(parent) # remove empty parent directory
|
remove_dir_if_empty(parent, ignore_metadata_caches=True)
|
||||||
else:
|
else:
|
||||||
os.makedirs(tpath)
|
os.makedirs(tpath)
|
||||||
update_paths_in_db()
|
update_paths_in_db()
|
||||||
|
@ -589,6 +589,24 @@ class WritingTest(BaseTest):
|
|||||||
|
|
||||||
def test_rename_items(self): # {{{
|
def test_rename_items(self): # {{{
|
||||||
' Test renaming of many-(many,one) items '
|
' Test renaming of many-(many,one) items '
|
||||||
|
# Test renaming authors removes folders with junk in them
|
||||||
|
cl = self.cloned_library
|
||||||
|
cache = self.init_cache(cl)
|
||||||
|
fmtpath = cache.format_abspath(1, 'FMT1')
|
||||||
|
bookpath = os.path.dirname(fmtpath)
|
||||||
|
authorpath = os.path.dirname(bookpath)
|
||||||
|
self.assertTrue(os.path.exists(authorpath))
|
||||||
|
author = cache.field_for('authors', 1)[0]
|
||||||
|
os.mkdir(os.path.join(authorpath, '.DS_Store'))
|
||||||
|
open(os.path.join(authorpath, 'Thumbs.db'), 'wb').close()
|
||||||
|
amap = {v:k for k, v in cache.get_id_map('authors').items()}
|
||||||
|
cache.rename_items('authors', {amap[author]: 'renamed'})
|
||||||
|
try:
|
||||||
|
items = os.listdir(authorpath)
|
||||||
|
except FileNotFoundError:
|
||||||
|
items = []
|
||||||
|
self.assertFalse(items, 'Items in author folder: ' + ' '.join(items))
|
||||||
|
|
||||||
cl = self.cloned_library
|
cl = self.cloned_library
|
||||||
cache = self.init_cache(cl)
|
cache = self.init_cache(cl)
|
||||||
# Check that renaming authors updates author sort and path
|
# Check that renaming authors updates author sort and path
|
||||||
@ -681,6 +699,7 @@ class WritingTest(BaseTest):
|
|||||||
self.assertEqual(c.field_for('tags', 1), ('r', 'q', 'c'))
|
self.assertEqual(c.field_for('tags', 1), ('r', 'q', 'c'))
|
||||||
self.assertEqual(c.field_for('tags', 2), ('X', 'y', 'z'))
|
self.assertEqual(c.field_for('tags', 2), ('X', 'y', 'z'))
|
||||||
self.assertEqual(c.field_for('tags', 3), ('a', 'X', 'z'))
|
self.assertEqual(c.field_for('tags', 3), ('a', 'X', 'z'))
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
def test_composite_cache(self): # {{{
|
def test_composite_cache(self): # {{{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user