From 3224a155a778058b68a1a200a921cc1b51a0d787 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 15 Jul 2014 11:49:03 +0900 Subject: [PATCH] normalize filenames as we sync user still needs to run "check media" if their fields are encoded incorrectly, but by fixing on the fly we'll ensure mediaSanity doesn't fail --- anki/media.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/anki/media.py b/anki/media.py index 7d37e8354..72f12e55f 100644 --- a/anki/media.py +++ b/anki/media.py @@ -384,6 +384,15 @@ create table meta (dirMod int, lastUsn int); insert into meta values (0, 0); if not os.path.getsize(f): os.unlink(f) continue + # check encoding + if not isMac: + normf = unicodedata.normalize("NFC", f) + if f != normf: + # wrong filename encoding which will cause sync errors + if os.path.exists(normf): + os.unlink(f) + else: + os.rename(f, normf) # newly added? if f not in self.cache: added.append(f)