mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix a regression that caused chaning the case of title/authors to no longer change the case of the actual files in the filesystem if the filesystem is case-insensitive
This commit is contained in:
parent
68a707bad3
commit
0ec96bae40
@ -947,23 +947,38 @@ class DB(object):
|
|||||||
if not isinstance(dest, basestring):
|
if not isinstance(dest, basestring):
|
||||||
raise Exception("Error, you must pass the dest as a path when"
|
raise Exception("Error, you must pass the dest as a path when"
|
||||||
" using windows_atomic_move")
|
" using windows_atomic_move")
|
||||||
if dest and not samefile(dest, path):
|
if dest:
|
||||||
windows_atomic_move.copy_path_to(path, dest)
|
if samefile(dest, path):
|
||||||
|
# Ensure that the file has the same case as dest
|
||||||
|
try:
|
||||||
|
os.rename(path, dest)
|
||||||
|
except:
|
||||||
|
pass # Nothing too catastrophic happened, the cases mismatch, that's all
|
||||||
|
else:
|
||||||
|
windows_atomic_move.copy_path_to(path, dest)
|
||||||
else:
|
else:
|
||||||
if hasattr(dest, 'write'):
|
if hasattr(dest, 'write'):
|
||||||
with lopen(path, 'rb') as f:
|
with lopen(path, 'rb') as f:
|
||||||
shutil.copyfileobj(f, dest)
|
shutil.copyfileobj(f, dest)
|
||||||
if hasattr(dest, 'flush'):
|
if hasattr(dest, 'flush'):
|
||||||
dest.flush()
|
dest.flush()
|
||||||
elif dest and not samefile(dest, path):
|
elif dest:
|
||||||
if use_hardlink:
|
if samefile(dest, path):
|
||||||
try:
|
if not self.is_case_sensitive:
|
||||||
hardlink_file(path, dest)
|
# Ensure that the file has the same case as dest
|
||||||
return True
|
try:
|
||||||
except:
|
os.rename(path, dest)
|
||||||
pass
|
except:
|
||||||
with lopen(path, 'rb') as f, lopen(dest, 'wb') as d:
|
pass # Nothing too catastrophic happened, the cases mismatch, that's all
|
||||||
shutil.copyfileobj(f, d)
|
else:
|
||||||
|
if use_hardlink:
|
||||||
|
try:
|
||||||
|
hardlink_file(path, dest)
|
||||||
|
return True
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
with lopen(path, 'rb') as f, lopen(dest, 'wb') as d:
|
||||||
|
shutil.copyfileobj(f, d)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def windows_check_if_files_in_use(self, paths):
|
def windows_check_if_files_in_use(self, paths):
|
||||||
|
@ -60,6 +60,12 @@ class FilesystemTest(BaseTest):
|
|||||||
fpath = c.format_abspath(1, 'FMT1').replace(os.sep, '/').split('/')
|
fpath = c.format_abspath(1, 'FMT1').replace(os.sep, '/').split('/')
|
||||||
ae(fpath[-3:], ['Moved', 'Moved (1)', 'Moved - Moved.fmt1'])
|
ae(fpath[-3:], ['Moved', 'Moved (1)', 'Moved - Moved.fmt1'])
|
||||||
af(os.path.exists(os.path.dirname(orig_fpath)), 'Original book folder still exists')
|
af(os.path.exists(os.path.dirname(orig_fpath)), 'Original book folder still exists')
|
||||||
|
# Check that the filesystem reflects fpath (especially on
|
||||||
|
# case-insensitive systems).
|
||||||
|
for x in range(1, 4):
|
||||||
|
base = os.sep.join(fpath[:-x])
|
||||||
|
part = fpath[-x:][0]
|
||||||
|
self.assertIn(part, os.listdir(base))
|
||||||
|
|
||||||
@unittest.skipUnless(iswindows, 'Windows only')
|
@unittest.skipUnless(iswindows, 'Windows only')
|
||||||
def test_windows_atomic_move(self):
|
def test_windows_atomic_move(self):
|
||||||
|
@ -1343,23 +1343,38 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
if not isinstance(dest, basestring):
|
if not isinstance(dest, basestring):
|
||||||
raise Exception("Error, you must pass the dest as a path when"
|
raise Exception("Error, you must pass the dest as a path when"
|
||||||
" using windows_atomic_move")
|
" using windows_atomic_move")
|
||||||
if dest and not samefile(dest, path):
|
if dest:
|
||||||
windows_atomic_move.copy_path_to(path, dest)
|
if samefile(path, dest):
|
||||||
|
# Ensure that the file has the same case as dest
|
||||||
|
try:
|
||||||
|
os.rename(path, dest)
|
||||||
|
except:
|
||||||
|
pass # Nothing too catastrophic happened, the cases mismatch, that's all
|
||||||
|
else:
|
||||||
|
windows_atomic_move.copy_path_to(path, dest)
|
||||||
else:
|
else:
|
||||||
if hasattr(dest, 'write'):
|
if hasattr(dest, 'write'):
|
||||||
with lopen(path, 'rb') as f:
|
with lopen(path, 'rb') as f:
|
||||||
shutil.copyfileobj(f, dest)
|
shutil.copyfileobj(f, dest)
|
||||||
if hasattr(dest, 'flush'):
|
if hasattr(dest, 'flush'):
|
||||||
dest.flush()
|
dest.flush()
|
||||||
elif dest and not samefile(dest, path):
|
elif dest:
|
||||||
if use_hardlink:
|
if samefile(dest, path):
|
||||||
try:
|
if not self.is_case_sensitive:
|
||||||
hardlink_file(path, dest)
|
# Ensure that the file has the same case as dest
|
||||||
return
|
try:
|
||||||
except:
|
os.rename(path, dest)
|
||||||
pass
|
except:
|
||||||
with lopen(path, 'rb') as f, lopen(dest, 'wb') as d:
|
pass # Nothing too catastrophic happened, the cases mismatch, that's all
|
||||||
shutil.copyfileobj(f, d)
|
else:
|
||||||
|
if use_hardlink:
|
||||||
|
try:
|
||||||
|
hardlink_file(path, dest)
|
||||||
|
return
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
with lopen(path, 'rb') as f, lopen(dest, 'wb') as d:
|
||||||
|
shutil.copyfileobj(f, d)
|
||||||
|
|
||||||
def copy_cover_to(self, index, dest, index_is_id=False,
|
def copy_cover_to(self, index, dest, index_is_id=False,
|
||||||
windows_atomic_move=None, use_hardlink=False):
|
windows_atomic_move=None, use_hardlink=False):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user