From 643e2e587ebdd00c3725766b4c077dff5f90e0fb Mon Sep 17 00:00:00 2001 From: j Date: Mon, 12 Jun 2017 16:49:08 +0200 Subject: [PATCH] some filesystems are case insensitive, always use case insensitive lookup --- oml/item/models.py | 4 ++-- oml/utils.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/oml/item/models.py b/oml/item/models.py index 7e12e83..ee6f2c1 100644 --- a/oml/item/models.py +++ b/oml/item/models.py @@ -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() diff --git a/oml/utils.py b/oml/utils.py index 71dc25e..cacf826 100644 --- a/oml/utils.py +++ b/oml/utils.py @@ -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