Fix font scanner not detecting when fonts are removed from the system

This commit is contained in:
Kovid Goyal 2012-11-02 07:47:39 +05:30
parent 24f5d071de
commit 0d9ea03fd4

View File

@ -161,12 +161,17 @@ class Scanner(Thread):
def do_scan(self): def do_scan(self):
self.reload_cache() self.reload_cache()
num = 0
if isworker:
# Dont scan font files in worker processes, use whatever is
# cached. Font files typically dont change frequently enough to
# justify a rescan in a worker process.
self.build_families()
return
cached_fonts = self.cached_fonts.copy()
self.cached_fonts.clear()
for folder in self.folders: for folder in self.folders:
if isworker:
# Dont scan font files in worker processes, use whatever is
# cached.
continue
if not os.path.isdir(folder): if not os.path.isdir(folder):
continue continue
try: try:
@ -186,7 +191,10 @@ class Scanner(Thread):
except EnvironmentError: except EnvironmentError:
continue continue
fileid = '{0}||{1}:{2}'.format(candidate, s.st_size, s.st_mtime) fileid = '{0}||{1}:{2}'.format(candidate, s.st_size, s.st_mtime)
if fileid in self.cached_fonts: if fileid in cached_fonts:
# Use previously cached metadata, since the file size and
# last modified timestamp have not changed.
self.cached_fonts[fileid] = cached_fonts[fileid]
continue continue
try: try:
self.read_font_metadata(candidate, fileid) self.read_font_metadata(candidate, fileid)
@ -195,12 +203,11 @@ class Scanner(Thread):
prints('Failed to read metadata from font file:', prints('Failed to read metadata from font file:',
candidate, as_unicode(e)) candidate, as_unicode(e))
continue continue
num += 1
if num >= 10: if frozenset(cached_fonts) != frozenset(self.cached_fonts):
num = 0 # Write out the cache only if some font files have changed
self.write_cache()
if num > 0:
self.write_cache() self.write_cache()
self.build_families() self.build_families()
def font_priority(self, font): def font_priority(self, font):