mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-05 21:23:49 +02:00
Use rmtree with retry when deleting after library move
Hopefully makes test failures more rare
This commit is contained in:
parent
b3a3eace49
commit
873d6080fd
1 changed files with 12 additions and 10 deletions
|
|
@ -386,6 +386,16 @@ def set_global_state(backend):
|
|||
backend.library_id, (), precompiled_user_functions=backend.get_user_template_functions())
|
||||
|
||||
|
||||
def rmtree_with_retry(path, sleep_time=1):
|
||||
try:
|
||||
shutil.rmtree(path)
|
||||
except EnvironmentError as e:
|
||||
if e.errno == errno.ENOENT and not os.path.exists(path):
|
||||
return
|
||||
time.sleep(sleep_time) # In case something has temporarily locked a file
|
||||
shutil.rmtree(path)
|
||||
|
||||
|
||||
class DB(object):
|
||||
|
||||
PATH_LIMIT = 40 if iswindows else 100
|
||||
|
|
@ -1216,15 +1226,7 @@ def is_deletable(self, path):
|
|||
|
||||
def rmtree(self, path):
|
||||
if self.is_deletable(path):
|
||||
try:
|
||||
shutil.rmtree(path)
|
||||
except EnvironmentError as e:
|
||||
if e.errno == errno.ENOENT and not os.path.exists(path):
|
||||
return
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
time.sleep(1) # In case something has temporarily locked a file
|
||||
shutil.rmtree(path)
|
||||
rmtree_with_retry(path)
|
||||
|
||||
def construct_path_name(self, book_id, title, author):
|
||||
'''
|
||||
|
|
@ -1980,7 +1982,7 @@ def move_library_to(self, all_paths, newloc, progress=(lambda item_name, item_co
|
|||
self._conn = None
|
||||
for loc in old_dirs:
|
||||
try:
|
||||
shutil.rmtree(loc)
|
||||
rmtree_with_retry(loc)
|
||||
except EnvironmentError as e:
|
||||
if os.path.exists(loc):
|
||||
prints('Failed to delete:', loc, 'with error:', as_unicode(e))
|
||||
|
|
|
|||
Loading…
Reference in a new issue