some filesystems are case insensitive, always use case insensitive lookup

This commit is contained in:
j 2017-06-12 16:49:08 +02:00
parent 7ec42cab8d
commit 643e2e587e
2 changed files with 13 additions and 2 deletions

View File

@ -732,7 +732,7 @@ class File(db.Model):
def move(self):
def format_underscores(string):
return re.sub(r'^\.|\.$|:|/|\?|<|>|\\|\*', '_', string)
return re.sub(r'^\.|\.$|:|/|\?|<|>|\\|\*|\||"', '_', string)
prefs = settings.preferences
prefix = os.sep.join(os.path.join(os.path.expanduser(prefs['libraryPath']), 'Books/').split('/'))
if not self.item:
@ -779,7 +779,7 @@ class File(db.Model):
if self.path == new_path:
return
h = ''
while os.path.exists(os.path.join(prefix, new_path)):
while utils.iexists(os.path.join(prefix, new_path)):
h = self.sha1[:len(h)+1]
filename = '%s.%s.%s' % (title, h, extension)
first = unicodedata.normalize('NFD', author[0].upper())[0].upper()

View File

@ -440,3 +440,14 @@ def send_debug():
settings.server['last_debug'] = timestamp
except:
logger.debug('failed to send debug information')
def iexists(path):
parts = path.split(os.sep)
name = parts[-1].lower()
if len(parts) == 1:
folder = '.'
else:
folder = os.path.dirname(path)
files = os.listdir(folder)
files = {os.path.basename(f).lower() for f in files}
return name in files