Really fix the global cache: make sure we're reading and writing the same
data format. Also match subdirectories when consuming cache information. Also check dates for global cache: a dir is out of date if it is newer than the global cache; scan it manually if that's the case.
This commit is contained in:
parent
f6ee3db5f0
commit
03a212e525
|
@ -2,6 +2,7 @@
|
||||||
* $RCSId: xc/lib/fontconfig/src/fccache.c,v 1.12 2002/08/22 07:36:44 keithp Exp $
|
* $RCSId: xc/lib/fontconfig/src/fccache.c,v 1.12 2002/08/22 07:36:44 keithp Exp $
|
||||||
*
|
*
|
||||||
* Copyright © 2000 Keith Packard
|
* Copyright © 2000 Keith Packard
|
||||||
|
* Copyright © 2005 Patrick Lam
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, distribute, and sell this software and its
|
* Permission to use, copy, modify, distribute, and sell this software and its
|
||||||
* documentation for any purpose is hereby granted without fee, provided that
|
* documentation for any purpose is hereby granted without fee, provided that
|
||||||
|
@ -68,7 +69,7 @@ FcCacheReadString (int fd, FcChar8 *dest, int len)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
return FcFalse;
|
return 0;
|
||||||
|
|
||||||
size = len;
|
size = len;
|
||||||
i = 0;
|
i = 0;
|
||||||
|
@ -147,6 +148,7 @@ FcGlobalCacheDestroy (FcGlobalCache *cache)
|
||||||
|
|
||||||
void
|
void
|
||||||
FcGlobalCacheLoad (FcGlobalCache *cache,
|
FcGlobalCacheLoad (FcGlobalCache *cache,
|
||||||
|
FcStrSet *staleDirs,
|
||||||
const FcChar8 *cache_file)
|
const FcChar8 *cache_file)
|
||||||
{
|
{
|
||||||
FcChar8 name_buf[8192];
|
FcChar8 name_buf[8192];
|
||||||
|
@ -155,6 +157,11 @@ FcGlobalCacheLoad (FcGlobalCache *cache,
|
||||||
char candidate_arch_machine_name[MACHINE_SIGNATURE_SIZE + 9];
|
char candidate_arch_machine_name[MACHINE_SIGNATURE_SIZE + 9];
|
||||||
off_t current_arch_start;
|
off_t current_arch_start;
|
||||||
|
|
||||||
|
struct stat cache_stat, dir_stat;
|
||||||
|
|
||||||
|
if (stat ((char *) cache_file, &cache_stat) < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
cache->fd = open ((char *) cache_file, O_RDONLY);
|
cache->fd = open ((char *) cache_file, O_RDONLY);
|
||||||
if (cache->fd == -1)
|
if (cache->fd == -1)
|
||||||
return;
|
return;
|
||||||
|
@ -168,8 +175,9 @@ FcGlobalCacheLoad (FcGlobalCache *cache,
|
||||||
goto bail0;
|
goto bail0;
|
||||||
|
|
||||||
lseek (cache->fd, current_arch_start, SEEK_SET);
|
lseek (cache->fd, current_arch_start, SEEK_SET);
|
||||||
if (FcCacheReadString (cache->fd, candidate_arch_machine_name,
|
FcCacheReadString (cache->fd, candidate_arch_machine_name,
|
||||||
sizeof (candidate_arch_machine_name)) == 0)
|
sizeof (candidate_arch_machine_name));
|
||||||
|
if (strlen(candidate_arch_machine_name) == 0)
|
||||||
goto bail0;
|
goto bail0;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
|
@ -178,6 +186,17 @@ FcGlobalCacheLoad (FcGlobalCache *cache,
|
||||||
if (!strlen(name_buf))
|
if (!strlen(name_buf))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
if (stat ((char *) name_buf, &dir_stat) < 0 ||
|
||||||
|
dir_stat.st_mtime > cache_stat.st_mtime)
|
||||||
|
{
|
||||||
|
FcCache md;
|
||||||
|
|
||||||
|
FcStrSetAdd (staleDirs, FcStrCopy (name_buf));
|
||||||
|
read (cache->fd, &md, sizeof (FcCache));
|
||||||
|
lseek (cache->fd, FcCacheNextOffset (lseek(cache->fd, 0, SEEK_CUR)) + md.count, SEEK_SET);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
d = malloc (sizeof (FcGlobalCacheDir));
|
d = malloc (sizeof (FcGlobalCacheDir));
|
||||||
if (!d)
|
if (!d)
|
||||||
goto bail1;
|
goto bail1;
|
||||||
|
@ -210,22 +229,24 @@ FcBool
|
||||||
FcGlobalCacheReadDir (FcFontSet *set, FcStrSet *dirs, FcGlobalCache * cache, const FcChar8 *dir, FcConfig *config)
|
FcGlobalCacheReadDir (FcFontSet *set, FcStrSet *dirs, FcGlobalCache * cache, const FcChar8 *dir, FcConfig *config)
|
||||||
{
|
{
|
||||||
FcGlobalCacheDir *d;
|
FcGlobalCacheDir *d;
|
||||||
|
FcBool ret = FcFalse;
|
||||||
|
|
||||||
if (cache->fd == -1)
|
if (cache->fd == -1)
|
||||||
return FcFalse;
|
return FcFalse;
|
||||||
|
|
||||||
for (d = cache->dirs; d; d = d->next)
|
for (d = cache->dirs; d; d = d->next)
|
||||||
{
|
{
|
||||||
if (strcmp (d->name, dir) == 0)
|
if (strncmp (d->name, dir, strlen(dir)) == 0)
|
||||||
{
|
{
|
||||||
lseek (cache->fd, d->offset, SEEK_SET);
|
lseek (cache->fd, d->offset, SEEK_SET);
|
||||||
if (!FcDirCacheConsume (cache->fd, set))
|
if (!FcDirCacheConsume (cache->fd, set))
|
||||||
return FcFalse;
|
return FcFalse;
|
||||||
return FcTrue;
|
if (strcmp (d->name, dir) == 0)
|
||||||
|
ret = FcTrue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return FcFalse;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
FcBool
|
FcBool
|
||||||
|
@ -302,7 +323,15 @@ FcGlobalCacheSave (FcGlobalCache *cache,
|
||||||
if (ftruncate (fd, current_arch_start) == -1)
|
if (ftruncate (fd, current_arch_start) == -1)
|
||||||
goto bail2;
|
goto bail2;
|
||||||
|
|
||||||
truncate_to = current_arch_start;
|
header = malloc (10 + strlen (current_arch_machine_name));
|
||||||
|
if (!header)
|
||||||
|
goto bail1;
|
||||||
|
sprintf (header, "%8x ", (int)truncate_to);
|
||||||
|
strcat (header, current_arch_machine_name);
|
||||||
|
if (!FcCacheWriteString (fd, header))
|
||||||
|
goto bail1;
|
||||||
|
|
||||||
|
truncate_to = current_arch_start + strlen(header) + 1;
|
||||||
for (dir = cache->dirs; dir; dir = dir->next)
|
for (dir = cache->dirs; dir; dir = dir->next)
|
||||||
{
|
{
|
||||||
truncate_to += strlen(dir->name) + 1;
|
truncate_to += strlen(dir->name) + 1;
|
||||||
|
@ -311,13 +340,6 @@ FcGlobalCacheSave (FcGlobalCache *cache,
|
||||||
truncate_to += dir->metadata.count;
|
truncate_to += dir->metadata.count;
|
||||||
}
|
}
|
||||||
truncate_to -= current_arch_start;
|
truncate_to -= current_arch_start;
|
||||||
header = malloc (10 + strlen (current_arch_machine_name));
|
|
||||||
if (!header)
|
|
||||||
goto bail1;
|
|
||||||
sprintf (header, "%8x ", (int)truncate_to);
|
|
||||||
strcat (header, current_arch_machine_name);
|
|
||||||
if (!FcCacheWriteString (fd, header))
|
|
||||||
goto bail1;
|
|
||||||
|
|
||||||
for (dir = cache->dirs; dir; dir = dir->next)
|
for (dir = cache->dirs; dir; dir = dir->next)
|
||||||
{
|
{
|
||||||
|
@ -485,8 +507,7 @@ FcCacheReadDirs (FcConfig * config, FcGlobalCache * cache,
|
||||||
struct stat statb;
|
struct stat statb;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now scan all of the directories into separate databases
|
* Read in the results from 'list'.
|
||||||
* and write out the results
|
|
||||||
*/
|
*/
|
||||||
while ((dir = FcStrListNext (list)))
|
while ((dir = FcStrListNext (list)))
|
||||||
{
|
{
|
||||||
|
@ -543,7 +564,7 @@ FcCacheReadDirs (FcConfig * config, FcGlobalCache * cache,
|
||||||
if (!FcDirCacheValid (dir) || !FcDirCacheRead (set, subdirs, dir))
|
if (!FcDirCacheValid (dir) || !FcDirCacheRead (set, subdirs, dir))
|
||||||
{
|
{
|
||||||
if (FcDebug () & FC_DBG_FONTSET)
|
if (FcDebug () & FC_DBG_FONTSET)
|
||||||
printf ("scan dir %s\n", dir);
|
printf ("cache scan dir %s\n", dir);
|
||||||
|
|
||||||
FcDirScanConfig (set, subdirs, cache,
|
FcDirScanConfig (set, subdirs, cache,
|
||||||
config->blanks, dir, FcFalse, config);
|
config->blanks, dir, FcFalse, config);
|
||||||
|
|
23
src/fccfg.c
23
src/fccfg.c
|
@ -250,6 +250,7 @@ FcConfigBuildFonts (FcConfig *config)
|
||||||
FcFontSet *fonts, *cached_fonts;
|
FcFontSet *fonts, *cached_fonts;
|
||||||
FcGlobalCache *cache;
|
FcGlobalCache *cache;
|
||||||
FcStrList *list;
|
FcStrList *list;
|
||||||
|
FcStrSet *oldDirs;
|
||||||
FcChar8 *dir;
|
FcChar8 *dir;
|
||||||
|
|
||||||
fonts = FcFontSetCreate ();
|
fonts = FcFontSetCreate ();
|
||||||
|
@ -260,20 +261,24 @@ FcConfigBuildFonts (FcConfig *config)
|
||||||
if (!cache)
|
if (!cache)
|
||||||
goto bail1;
|
goto bail1;
|
||||||
|
|
||||||
|
oldDirs = FcStrSetCreate ();
|
||||||
|
if (!oldDirs)
|
||||||
|
goto bail2;
|
||||||
|
|
||||||
if (config->cache)
|
if (config->cache)
|
||||||
FcGlobalCacheLoad (cache, config->cache);
|
FcGlobalCacheLoad (cache, oldDirs, config->cache);
|
||||||
|
|
||||||
cached_fonts = FcCacheRead(config, cache);
|
cached_fonts = FcCacheRead(config, cache);
|
||||||
if (!cached_fonts)
|
if (!cached_fonts)
|
||||||
{
|
{
|
||||||
list = FcConfigGetFontDirs (config);
|
list = FcConfigGetFontDirs (config);
|
||||||
if (!list)
|
if (!list)
|
||||||
goto bail1;
|
goto bail2;
|
||||||
|
|
||||||
while ((dir = FcStrListNext (list)))
|
while ((dir = FcStrListNext (list)))
|
||||||
{
|
{
|
||||||
if (FcDebug () & FC_DBG_FONTSET)
|
if (FcDebug () & FC_DBG_FONTSET)
|
||||||
printf ("scan dir %s\n", dir);
|
printf ("build scan dir %s\n", dir);
|
||||||
FcDirScanConfig (fonts, config->fontDirs, cache,
|
FcDirScanConfig (fonts, config->fontDirs, cache,
|
||||||
config->blanks, dir, FcFalse, config);
|
config->blanks, dir, FcFalse, config);
|
||||||
}
|
}
|
||||||
|
@ -284,6 +289,15 @@ FcConfigBuildFonts (FcConfig *config)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < oldDirs->num; i++)
|
||||||
|
{
|
||||||
|
if (FcDebug () & FC_DBG_FONTSET)
|
||||||
|
printf ("scan dir %s\n", dir);
|
||||||
|
FcDirScanConfig (fonts, config->fontDirs, cache,
|
||||||
|
config->blanks, oldDirs->strs[i],
|
||||||
|
FcFalse, config);
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < cached_fonts->nfont; i++)
|
for (i = 0; i < cached_fonts->nfont; i++)
|
||||||
{
|
{
|
||||||
if (FcConfigAcceptFont (config, cached_fonts->fonts[i]))
|
if (FcConfigAcceptFont (config, cached_fonts->fonts[i]))
|
||||||
|
@ -301,10 +315,13 @@ FcConfigBuildFonts (FcConfig *config)
|
||||||
if (config->cache)
|
if (config->cache)
|
||||||
FcGlobalCacheSave (cache, config->cache);
|
FcGlobalCacheSave (cache, config->cache);
|
||||||
FcGlobalCacheDestroy (cache);
|
FcGlobalCacheDestroy (cache);
|
||||||
|
FcStrSetDestroy (oldDirs);
|
||||||
|
|
||||||
FcConfigSetFonts (config, fonts, FcSetSystem);
|
FcConfigSetFonts (config, fonts, FcSetSystem);
|
||||||
|
|
||||||
return FcTrue;
|
return FcTrue;
|
||||||
|
bail2:
|
||||||
|
FcStrSetDestroy (oldDirs);
|
||||||
bail1:
|
bail1:
|
||||||
FcFontSetDestroy (fonts);
|
FcFontSetDestroy (fonts);
|
||||||
bail0:
|
bail0:
|
||||||
|
|
|
@ -427,6 +427,7 @@ FcGlobalCacheReadDir (FcFontSet *set,
|
||||||
|
|
||||||
void
|
void
|
||||||
FcGlobalCacheLoad (FcGlobalCache *cache,
|
FcGlobalCacheLoad (FcGlobalCache *cache,
|
||||||
|
FcStrSet *staleDirs,
|
||||||
const FcChar8 *cache_file);
|
const FcChar8 *cache_file);
|
||||||
|
|
||||||
FcBool
|
FcBool
|
||||||
|
|
Loading…
Reference in New Issue