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,7 +947,14 @@ 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:
|
||||||
|
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)
|
windows_atomic_move.copy_path_to(path, dest)
|
||||||
else:
|
else:
|
||||||
if hasattr(dest, 'write'):
|
if hasattr(dest, 'write'):
|
||||||
@ -955,7 +962,15 @@ class DB(object):
|
|||||||
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 samefile(dest, path):
|
||||||
|
if not self.is_case_sensitive:
|
||||||
|
# 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:
|
||||||
if use_hardlink:
|
if use_hardlink:
|
||||||
try:
|
try:
|
||||||
hardlink_file(path, dest)
|
hardlink_file(path, dest)
|
||||||
|
@ -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,7 +1343,14 @@ 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:
|
||||||
|
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)
|
windows_atomic_move.copy_path_to(path, dest)
|
||||||
else:
|
else:
|
||||||
if hasattr(dest, 'write'):
|
if hasattr(dest, 'write'):
|
||||||
@ -1351,7 +1358,15 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
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 samefile(dest, path):
|
||||||
|
if not self.is_case_sensitive:
|
||||||
|
# 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:
|
||||||
if use_hardlink:
|
if use_hardlink:
|
||||||
try:
|
try:
|
||||||
hardlink_file(path, dest)
|
hardlink_file(path, dest)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user