compare NFC

This commit is contained in:
j 2019-01-14 20:32:34 +05:30
parent 88f9f2d27e
commit 52f45beaec
4 changed files with 11 additions and 7 deletions

View file

@ -3,6 +3,7 @@
import json
import hashlib
import os
import unicodedata
from sqlalchemy.orm import load_only
from sqlalchemy.sql.expression import text
@ -211,6 +212,7 @@ def autocomplete(data):
qs = qs.filter(models.Find.item_id.in_(items))
if data['value']:
value = data['value'].lower()
value = unicodedata.normalize('NFKD', value)
qs = qs.filter(models.Find.key.is_(data['key']))
if op == '=':
qs = qs.filter(models.Find.findvalue.contains(value))

View file

@ -23,7 +23,7 @@ from .icons import icons
from .person import get_sort_name, Person
from queryparser import Parser
from settings import config
from utils import remove_empty_folders, get_ratio
from utils import remove_empty_folders, get_ratio, same_path
from websocket import trigger_event
import db
import media
@ -788,7 +788,7 @@ class File(db.Model):
new_path = os.path.join(first, author, filename)
if current_path == os.path.join(prefix, new_path):
break
if unicodedata.normalize('NFD', self.path) != unicodedata.normalize('NFD', new_path):
if not same_path(self.path, new_path):
path = os.path.join(prefix, new_path)
ox.makedirs(os.path.dirname(path))
mode = 0o644

View file

@ -14,7 +14,7 @@ import ox
from changelog import add_record
from item.models import File, Item
from user.models import List
from utils import remove_empty_folders
from utils import remove_empty_folders, same_path
from websocket import trigger_event
import db
import media
@ -132,8 +132,6 @@ 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')
@ -155,7 +153,7 @@ def run_scan():
if file:
f1 = file.fullpath()
f2 = os.path.join(prefix, f)
if not nfd_same(f1, f2) and os.path.exists(f1) and os.path.exists(f2):
if not same_path(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)
@ -166,7 +164,7 @@ def run_scan():
if file:
f1 = file.fullpath()
f2 = os.path.join(prefix, f)
if not nfd_same(f1, f2) and os.path.exists(f1) and os.path.exists(f2):
if not same_path(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)

View file

@ -15,6 +15,7 @@ import stdnum.isbn
import subprocess
import sys
import time
import unicodedata
import ox
from OpenSSL.crypto import (
@ -462,3 +463,6 @@ def iexists(path):
return False
files = {os.path.basename(f).lower() for f in files}
return name in files
def same_path(f1, f2):
return unicodedata.normalize('NFC', f1) == unicodedata.normalize('NFC', f2)