only compare NFD value, never change path
This commit is contained in:
parent
c862faddd1
commit
7d0d473acd
1 changed files with 10 additions and 9 deletions
|
@ -32,7 +32,6 @@ def remove_missing(books=None):
|
||||||
prefix = get_prefix()
|
prefix = get_prefix()
|
||||||
if books is None:
|
if books is None:
|
||||||
books = collect_books(prefix)
|
books = collect_books(prefix)
|
||||||
books = [unicodedata.normalize('NFD', path) for path in books]
|
|
||||||
with db.session():
|
with db.session():
|
||||||
if os.path.exists(prefix):
|
if os.path.exists(prefix):
|
||||||
logger.debug('scan for removed files')
|
logger.debug('scan for removed files')
|
||||||
|
@ -42,7 +41,6 @@ def remove_missing(books=None):
|
||||||
if state.shutdown:
|
if state.shutdown:
|
||||||
return
|
return
|
||||||
path = f.fullpath()
|
path = f.fullpath()
|
||||||
path = unicodedata.normalize('NFD', path)
|
|
||||||
db_paths.append(path)
|
db_paths.append(path)
|
||||||
if f.item:
|
if f.item:
|
||||||
items[path] = f.sha1
|
items[path] = f.sha1
|
||||||
|
@ -52,7 +50,11 @@ def remove_missing(books=None):
|
||||||
if dirty:
|
if dirty:
|
||||||
state.db.session.commit()
|
state.db.session.commit()
|
||||||
dirty = False
|
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:
|
if removed:
|
||||||
logger.debug('%s files removed', len(removed))
|
logger.debug('%s files removed', len(removed))
|
||||||
ids = [items[path] for path in 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))
|
logger.debug('found %s books', len(books))
|
||||||
return books
|
return books
|
||||||
|
|
||||||
|
def nfd_same(f1, f2):
|
||||||
|
return unicodedata.normalize('NFD', f1) == unicodedata.normalize('NFD', f2)
|
||||||
|
|
||||||
def run_scan():
|
def run_scan():
|
||||||
logger.debug('run_scan')
|
logger.debug('run_scan')
|
||||||
prefix = get_prefix()
|
prefix = get_prefix()
|
||||||
|
@ -150,9 +155,7 @@ def run_scan():
|
||||||
if file:
|
if file:
|
||||||
f1 = file.fullpath()
|
f1 = file.fullpath()
|
||||||
f2 = os.path.join(prefix, f)
|
f2 = os.path.join(prefix, f)
|
||||||
f1 = unicodedata.normalize('NFD', f1)
|
if not nfd_same(f1, f2) and os.path.exists(f1) and os.path.exists(f2):
|
||||||
f2 = unicodedata.normalize('NFD', f2)
|
|
||||||
if f1 != f2 and os.path.exists(f1) and os.path.exists(f2):
|
|
||||||
logger.debug('file exists in multiple locations %s', id)
|
logger.debug('file exists in multiple locations %s', id)
|
||||||
logger.debug('"%s" vs "%s"', f1, f2)
|
logger.debug('"%s" vs "%s"', f1, f2)
|
||||||
os.chmod(f2, stat.S_IWRITE)
|
os.chmod(f2, stat.S_IWRITE)
|
||||||
|
@ -163,9 +166,7 @@ def run_scan():
|
||||||
if file:
|
if file:
|
||||||
f1 = file.fullpath()
|
f1 = file.fullpath()
|
||||||
f2 = os.path.join(prefix, f)
|
f2 = os.path.join(prefix, f)
|
||||||
f1 = unicodedata.normalize('NFD', f1)
|
if not nfd_same(f1, f2) and os.path.exists(f1) and os.path.exists(f2):
|
||||||
f2 = unicodedata.normalize('NFD', f2)
|
|
||||||
if f1 != f2 and os.path.exists(f1) and os.path.exists(f2):
|
|
||||||
logger.debug('"%s" vs "%s"', f1, f2)
|
logger.debug('"%s" vs "%s"', f1, f2)
|
||||||
os.chmod(f2, stat.S_IWRITE)
|
os.chmod(f2, stat.S_IWRITE)
|
||||||
os.unlink(f2)
|
os.unlink(f2)
|
||||||
|
|
Loading…
Reference in a new issue