mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
When restoring a db on windows if renaming the old db fails because some other process has locked the file, wait a little and try again
This commit is contained in:
parent
1fa5a5af1a
commit
c2246fdd5a
@ -5,7 +5,7 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import re, os, traceback, shutil
|
import re, os, traceback, shutil, time
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
|
|
||||||
@ -269,7 +269,14 @@ class Restore(Thread):
|
|||||||
save_path = self.olddb = os.path.splitext(dbpath)[0]+'_pre_restore.db'
|
save_path = self.olddb = os.path.splitext(dbpath)[0]+'_pre_restore.db'
|
||||||
if os.path.exists(save_path):
|
if os.path.exists(save_path):
|
||||||
os.remove(save_path)
|
os.remove(save_path)
|
||||||
os.rename(dbpath, save_path)
|
try:
|
||||||
|
os.rename(dbpath, save_path)
|
||||||
|
except OSError as err:
|
||||||
|
if getattr(err, 'winerror', None) == 32: # ERROR_SHARING_VIOLATION
|
||||||
|
time.sleep(4) # Wait a little for dropbox or the antivirus or whatever to release the file
|
||||||
|
os.rename(dbpath, save_path)
|
||||||
|
else:
|
||||||
|
raise
|
||||||
shutil.copyfile(ndbpath, dbpath)
|
shutil.copyfile(ndbpath, dbpath)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user