mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Restore case renaming code, but in a more robust form
This commit is contained in:
parent
c406114722
commit
2bd3bda0fe
@ -451,9 +451,6 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
parent = os.path.dirname(spath)
|
parent = os.path.dirname(spath)
|
||||||
if len(os.listdir(parent)) == 0:
|
if len(os.listdir(parent)) == 0:
|
||||||
self.rmtree(parent, permanent=True)
|
self.rmtree(parent, permanent=True)
|
||||||
'''
|
|
||||||
This is commented out as it can lead to book file loss if the second
|
|
||||||
rename fails. This makes it not worthwhile, IMO.
|
|
||||||
|
|
||||||
curpath = self.library_path
|
curpath = self.library_path
|
||||||
c1, c2 = current_path.split('/'), path.split('/')
|
c1, c2 = current_path.split('/'), path.split('/')
|
||||||
@ -469,15 +466,11 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
# the directories, so no need to do them here.
|
# the directories, so no need to do them here.
|
||||||
for oldseg, newseg in zip(c1, c2):
|
for oldseg, newseg in zip(c1, c2):
|
||||||
if oldseg.lower() == newseg.lower() and oldseg != newseg:
|
if oldseg.lower() == newseg.lower() and oldseg != newseg:
|
||||||
while True:
|
try:
|
||||||
# need a temp name in the current segment for renames
|
os.rename(os.path.join(curpath, oldseg), os.path.join(curpath, newseg))
|
||||||
tempname = os.path.join(curpath, 'TEMP.%f'%time.time())
|
except:
|
||||||
if not os.path.exists(tempname):
|
break # Fail silently since nothing catastrophic has happened
|
||||||
break
|
|
||||||
os.rename(os.path.join(curpath, oldseg), tempname)
|
|
||||||
os.rename(tempname, os.path.join(curpath, newseg))
|
|
||||||
curpath = os.path.join(curpath, newseg)
|
curpath = os.path.join(curpath, newseg)
|
||||||
'''
|
|
||||||
|
|
||||||
def add_listener(self, listener):
|
def add_listener(self, listener):
|
||||||
'''
|
'''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user