if we renamed any files to nfc, need to rerun check

This commit is contained in:
Damien Elmes 2013-12-13 20:24:39 +09:00
parent ab81227dac
commit f0525a76fb
2 changed files with 8 additions and 1 deletions

View file

@ -30,6 +30,6 @@ if arch[1] == "ELF":
sys.path.insert(0, os.path.join(ext, "py2.%d-%s" % ( sys.path.insert(0, os.path.join(ext, "py2.%d-%s" % (
sys.version_info[1], arch[0][0:2]))) sys.version_info[1], arch[0][0:2])))
version="2.0.19" # build scripts grep this line, so preserve formatting version="2.0.20" # build scripts grep this line, so preserve formatting
from anki.storage import Collection from anki.storage import Collection
__all__ = ["Collection"] __all__ = ["Collection"]

View file

@ -217,6 +217,7 @@ class MediaManager(object):
files = os.listdir(mdir) files = os.listdir(mdir)
else: else:
files = local files = local
renamedFiles = False
for file in files: for file in files:
if not local: if not local:
if not os.path.isfile(file): if not os.path.isfile(file):
@ -236,14 +237,20 @@ class MediaManager(object):
# delete if we already have the NFC form, otherwise rename # delete if we already have the NFC form, otherwise rename
if os.path.exists(nfcFile): if os.path.exists(nfcFile):
os.unlink(file) os.unlink(file)
renamedFiles = True
else: else:
os.rename(file, nfcFile) os.rename(file, nfcFile)
renamedFiles = True
file = nfcFile file = nfcFile
# compare # compare
if nfcFile not in allRefs: if nfcFile not in allRefs:
unused.append(file) unused.append(file)
else: else:
allRefs.discard(nfcFile) allRefs.discard(nfcFile)
# if we renamed any files to nfc format, we must rerun the check
# to make sure the renamed files are not marked as unused
if renamedFiles:
return self.check(local=local)
nohave = [x for x in allRefs if not x.startswith("_")] nohave = [x for x in allRefs if not x.startswith("_")]
return (nohave, unused, invalid) return (nohave, unused, invalid)