only compare NFD value, never change path

This commit is contained in:
j 2019-01-14 17:58:34 +05:30
parent c862faddd1
commit 7d0d473acd
1 changed files with 10 additions and 9 deletions

View File

@ -32,7 +32,6 @@ def remove_missing(books=None):
prefix = get_prefix()
if books is None:
books = collect_books(prefix)
books = [unicodedata.normalize('NFD', path) for path in books]
with db.session():
if os.path.exists(prefix):
logger.debug('scan for removed files')
@ -42,7 +41,6 @@ def remove_missing(books=None):
if state.shutdown:
return
path = f.fullpath()
path = unicodedata.normalize('NFD', path)
db_paths.append(path)
if f.item:
items[path] = f.sha1
@ -52,7 +50,11 @@ def remove_missing(books=None):
if dirty:
state.db.session.commit()
dirty = False
removed = set(db_paths) - set(books)
nfd_books = {unicodedata.normalize('NFD', path) for path in nfd_books}
removed = [
path for path in db_paths
if unicodedata.normalize('NFD', path) not in nfd_books
]
if removed:
logger.debug('%s files removed', len(removed))
ids = [items[path] for path in removed]
@ -130,6 +132,9 @@ def collect_books(prefix, status=None):
logger.debug('found %s books', len(books))
return books
def nfd_same(f1, f2):
return unicodedata.normalize('NFD', f1) == unicodedata.normalize('NFD', f2)
def run_scan():
logger.debug('run_scan')
prefix = get_prefix()
@ -150,9 +155,7 @@ def run_scan():
if file:
f1 = file.fullpath()
f2 = os.path.join(prefix, f)
f1 = unicodedata.normalize('NFD', f1)
f2 = unicodedata.normalize('NFD', f2)
if f1 != f2 and os.path.exists(f1) and os.path.exists(f2):
if not nfd_same(f1, f2) and os.path.exists(f1) and os.path.exists(f2):
logger.debug('file exists in multiple locations %s', id)
logger.debug('"%s" vs "%s"', f1, f2)
os.chmod(f2, stat.S_IWRITE)
@ -163,9 +166,7 @@ def run_scan():
if file:
f1 = file.fullpath()
f2 = os.path.join(prefix, f)
f1 = unicodedata.normalize('NFD', f1)
f2 = unicodedata.normalize('NFD', f2)
if f1 != f2 and os.path.exists(f1) and os.path.exists(f2):
if not nfd_same(f1, f2) and os.path.exists(f1) and os.path.exists(f2):
logger.debug('"%s" vs "%s"', f1, f2)
os.chmod(f2, stat.S_IWRITE)
os.unlink(f2)