Eliminate global cache. Eliminate multi-arch cache code.

With the removal of the in-directory cache files, and the addition of
per-user cache directories, there is no longer any reason to preserve the
giant global cache file. Eliminating of this unifies the cache structure
and simplifies the overall caching strategies greatly.
This commit is contained in:
Keith Packard 2006-08-27 21:53:48 -07:00
parent cf65c0557e
commit 00f059e930
5 changed files with 203 additions and 1108 deletions

View File

@ -227,8 +227,7 @@ scanDirs (FcStrList *list, FcConfig *config, char *program, FcBool force, FcBool
ret++; ret++;
continue; continue;
} }
if (!force && FcDirCacheValid (dir, config) && if (!force && FcDirCacheValid (dir, config))
FcDirCacheHasCurrentArch (dir, config))
{ {
if (verbose) if (verbose)
printf ("skipping, %d fonts, %d dirs\n", printf ("skipping, %d fonts, %d dirs\n",

File diff suppressed because it is too large Load Diff

View File

@ -265,7 +265,6 @@ FcBool
FcConfigBuildFonts (FcConfig *config) FcConfigBuildFonts (FcConfig *config)
{ {
FcFontSet *fonts, *cached_fonts; FcFontSet *fonts, *cached_fonts;
FcGlobalCache *cache;
FcStrList *list; FcStrList *list;
FcStrSet *oldDirs; FcStrSet *oldDirs;
FcChar8 *dir; FcChar8 *dir;
@ -274,18 +273,11 @@ FcConfigBuildFonts (FcConfig *config)
if (!fonts) if (!fonts)
goto bail0; goto bail0;
cache = FcGlobalCacheCreate ();
if (!cache)
goto bail1;
oldDirs = FcStrSetCreate (); oldDirs = FcStrSetCreate ();
if (!oldDirs) if (!oldDirs)
goto bail2; goto bail2;
if (config->cache) cached_fonts = FcCacheRead(config);
FcGlobalCacheLoad (cache, oldDirs, config->cache, config);
cached_fonts = FcCacheRead(config, cache);
if (!cached_fonts) if (!cached_fonts)
{ {
list = FcConfigGetFontDirs (config); list = FcConfigGetFontDirs (config);
@ -296,7 +288,7 @@ FcConfigBuildFonts (FcConfig *config)
{ {
if (FcDebug () & FC_DBG_FONTSET) if (FcDebug () & FC_DBG_FONTSET)
printf ("build scan dir %s\n", dir); printf ("build scan dir %s\n", dir);
FcDirScanConfig (fonts, config->fontDirs, cache, FcDirScanConfig (fonts, config->fontDirs,
config->blanks, dir, FcFalse, config); config->blanks, dir, FcFalse, config);
} }
@ -310,7 +302,7 @@ FcConfigBuildFonts (FcConfig *config)
{ {
if (FcDebug () & FC_DBG_FONTSET) if (FcDebug () & FC_DBG_FONTSET)
printf ("scan dir %s\n", oldDirs->strs[i]); printf ("scan dir %s\n", oldDirs->strs[i]);
FcDirScanConfig (fonts, config->fontDirs, cache, FcDirScanConfig (fonts, config->fontDirs,
config->blanks, oldDirs->strs[i], config->blanks, oldDirs->strs[i],
FcFalse, config); FcFalse, config);
} }
@ -333,9 +325,6 @@ FcConfigBuildFonts (FcConfig *config)
if (FcDebug () & FC_DBG_FONTSET) if (FcDebug () & FC_DBG_FONTSET)
FcFontSetPrint (fonts); FcFontSetPrint (fonts);
if (config->cache)
FcGlobalCacheSave (cache, config->cache, config);
FcGlobalCacheDestroy (cache);
FcStrSetDestroy (oldDirs); FcStrSetDestroy (oldDirs);
FcConfigSetFonts (config, fonts, FcSetSystem); FcConfigSetFonts (config, fonts, FcSetSystem);
@ -344,8 +333,6 @@ FcConfigBuildFonts (FcConfig *config)
bail3: bail3:
FcStrSetDestroy (oldDirs); FcStrSetDestroy (oldDirs);
bail2: bail2:
FcGlobalCacheDestroy (cache);
bail1:
FcFontSetDestroy (fonts); FcFontSetDestroy (fonts);
bail0: bail0:
return FcFalse; return FcFalse;
@ -1799,7 +1786,7 @@ FcConfigAppFontAddFile (FcConfig *config,
FcConfigSetFonts (config, set, FcSetApplication); FcConfigSetFonts (config, set, FcSetApplication);
} }
if (!FcFileScanConfig (set, subdirs, 0, config->blanks, file, FcFalse, config)) if (!FcFileScanConfig (set, subdirs, config->blanks, file, FcFalse, config))
{ {
FcStrSetDestroy (subdirs); FcStrSetDestroy (subdirs);
return FcFalse; return FcFalse;
@ -1847,7 +1834,7 @@ FcConfigAppFontAddDir (FcConfig *config,
FcConfigSetFonts (config, set, FcSetApplication); FcConfigSetFonts (config, set, FcSetApplication);
} }
if (!FcDirScanConfig (set, subdirs, 0, config->blanks, dir, FcFalse, config)) if (!FcDirScanConfig (set, subdirs, config->blanks, dir, FcFalse, config))
{ {
FcStrSetDestroy (subdirs); FcStrSetDestroy (subdirs);
return FcFalse; return FcFalse;

View File

@ -35,26 +35,17 @@ FcFileIsDir (const FcChar8 *file)
return S_ISDIR(statb.st_mode); return S_ISDIR(statb.st_mode);
} }
FcBool static FcBool
FcFileScanConfig (FcFontSet *set, FcFileScanFontConfig (FcFontSet *set,
FcStrSet *dirs,
FcGlobalCache *cache,
FcBlanks *blanks, FcBlanks *blanks,
const FcChar8 *file, const FcChar8 *file,
FcBool force,
FcConfig *config) FcConfig *config)
{ {
int id;
FcPattern *font; FcPattern *font;
FcBool ret = FcTrue; FcBool ret = FcTrue;
int id;
int count = 0; int count = 0;
if (config && !FcConfigAcceptFilename (config, file))
return FcTrue;
if (FcFileIsDir (file))
return FcStrSetAdd (dirs, file);
id = 0; id = 0;
do do
{ {
@ -89,15 +80,32 @@ FcFileScanConfig (FcFontSet *set,
return ret; return ret;
} }
FcBool
FcFileScanConfig (FcFontSet *set,
FcStrSet *dirs,
FcBlanks *blanks,
const FcChar8 *file,
FcBool force,
FcConfig *config)
{
if (config && !FcConfigAcceptFilename (config, file))
return FcTrue;
if (FcFileIsDir (file))
return FcStrSetAdd (dirs, file);
else
return FcFileScanFontConfig (set, blanks, file, config);
}
FcBool FcBool
FcFileScan (FcFontSet *set, FcFileScan (FcFontSet *set,
FcStrSet *dirs, FcStrSet *dirs,
FcGlobalCache *cache, FcFileCache *cache, /* XXX unused */
FcBlanks *blanks, FcBlanks *blanks,
const FcChar8 *file, const FcChar8 *file,
FcBool force) FcBool force)
{ {
return FcFileScanConfig (set, dirs, cache, blanks, file, force, 0); return FcFileScanConfig (set, dirs, blanks, file, force, 0);
} }
/* /*
@ -118,7 +126,6 @@ cmpstringp(const void *p1, const void *p2)
FcBool FcBool
FcDirScanConfig (FcFontSet *set, FcDirScanConfig (FcFontSet *set,
FcStrSet *dirs, FcStrSet *dirs,
FcGlobalCache *cache,
FcBlanks *blanks, FcBlanks *blanks,
const FcChar8 *dir, const FcChar8 *dir,
FcBool force, FcBool force,
@ -126,8 +133,7 @@ FcDirScanConfig (FcFontSet *set,
{ {
DIR *d; DIR *d;
struct dirent *e; struct dirent *e;
FcChar8 **dirlist; FcStrSet *dirlist, *filelist;
int dirlistlen, dirlistalloc;
FcChar8 *file; FcChar8 *file;
FcChar8 *base; FcChar8 *base;
FcBool ret = FcTrue; FcBool ret = FcTrue;
@ -139,18 +145,13 @@ FcDirScanConfig (FcFontSet *set,
if (!force) if (!force)
{ {
/* if (FcDirCacheRead (set, dirs, dir, config))
* Check ~/.fonts.cache-<version> file
*/
if (cache && FcGlobalCacheReadDir (set, dirs, cache, (char *)dir, config))
return FcTrue;
if (FcDirCacheValid (dir, config) &&
FcDirCacheHasCurrentArch (dir, config) &&
FcDirCacheRead (set, dirs, dir, config))
return FcTrue; return FcTrue;
} }
if (FcDebug () & FC_DBG_FONTSET)
printf ("cache scan dir %s\n", dir);
/* freed below */ /* freed below */
file = (FcChar8 *) malloc (strlen ((char *) dir) + 1 + FC_MAX_FILE_LEN + 1); file = (FcChar8 *) malloc (strlen ((char *) dir) + 1 + FC_MAX_FILE_LEN + 1);
if (!file) if (!file)
@ -180,75 +181,80 @@ FcDirScanConfig (FcFontSet *set,
goto bail0; goto bail0;
} }
dirlistlen = 0; dirlist = FcStrSetCreate ();
dirlistalloc = 8;
dirlist = malloc(dirlistalloc * sizeof(FcChar8 *));
if (!dirlist) if (!dirlist)
{ {
ret = FcFalse; ret = FcFalse;
goto bail1; goto bail1;
} }
filelist = FcStrSetCreate ();
if (!filelist)
{
ret = FcFalse;
goto bail2;
}
while ((e = readdir (d))) while ((e = readdir (d)))
{ {
if (e->d_name[0] != '.' && strlen (e->d_name) < FC_MAX_FILE_LEN) if (e->d_name[0] != '.' && strlen (e->d_name) < FC_MAX_FILE_LEN)
{ {
if (dirlistlen == dirlistalloc) strcpy ((char *) base, (char *) e->d_name);
{ if (FcFileIsDir (file)) {
FcChar8 **tmp_dirlist; if (!FcStrSetAdd (dirlist, file)) {
dirlistalloc *= 2;
tmp_dirlist = realloc(dirlist,
dirlistalloc * sizeof(FcChar8 *));
if (!tmp_dirlist)
{
ret = FcFalse; ret = FcFalse;
goto bail2; goto bail3;
} }
dirlist = tmp_dirlist; } else {
} if (!FcStrSetAdd (filelist, file)) {
dirlist[dirlistlen] = malloc(strlen (e->d_name) + 1);
if (!dirlist[dirlistlen])
{
ret = FcFalse; ret = FcFalse;
goto bail2; goto bail3;
} }
strcpy((char *)dirlist[dirlistlen], e->d_name);
dirlistlen++;
} }
} }
qsort(dirlist, dirlistlen, sizeof(FcChar8 *), cmpstringp);
i = 0;
while (ret && i < dirlistlen)
{
strcpy ((char *) base, (char *) dirlist[i]);
ret = FcFileScanConfig (tmpSet, dirs, cache, blanks, file, force, config);
i++;
} }
/* /*
* Now that the directory has been scanned, * Sort files and dirs to make things prettier
* add the cache entry
*/ */
if (ret && cache) qsort(dirlist->strs, dirlist->num, sizeof(FcChar8 *), cmpstringp);
FcGlobalCacheUpdate (cache, dirs, (char *)dir, tmpSet, config); qsort(filelist->strs, filelist->num, sizeof(FcChar8 *), cmpstringp);
for (i = 0; i < filelist->num; i++)
FcFileScanFontConfig (tmpSet, blanks, filelist->strs[i], config);
if (FcShouldWriteFiles ())
{
/*
* Now that the directory has been scanned,
* write out the cache file
*/
FcDirCacheWrite (tmpSet, dirlist, dir, config);
}
/*
* Add the discovered fonts to our internal non-cache list
*/
for (i = 0; i < tmpSet->nfont; i++) for (i = 0; i < tmpSet->nfont; i++)
FcFontSetAdd (set, tmpSet->fonts[i]); FcFontSetAdd (set, tmpSet->fonts[i]);
if (tmpSet->fonts) /*
{ * the patterns in tmpset now belong to set; don't free them
FcMemFree (FC_MEM_FONTPTR, tmpSet->sfont * sizeof (FcPattern *)); */
free (tmpSet->fonts); tmpSet->nfont = 0;
/*
* Add the discovered directories to the list to be scanned
*/
for (i = 0; i < dirlist->num; i++)
if (!FcStrSetAdd (dirs, dirlist->strs[i])) {
ret = FcFalse;
goto bail3;
} }
FcMemFree (FC_MEM_FONTSET, sizeof (FcFontSet));
bail3:
FcStrSetDestroy (filelist);
bail2: bail2:
for (i = 0; i < dirlistlen; i++) FcStrSetDestroy (dirlist);
free(dirlist[i]);
free (dirlist);
bail1: bail1:
free (tmpSet); FcFontSetDestroy (tmpSet);
bail0: bail0:
closedir (d); closedir (d);
@ -260,12 +266,12 @@ FcDirScanConfig (FcFontSet *set,
FcBool FcBool
FcDirScan (FcFontSet *set, FcDirScan (FcFontSet *set,
FcStrSet *dirs, FcStrSet *dirs,
FcGlobalCache *cache, FcFileCache *cache, /* XXX unused */
FcBlanks *blanks, FcBlanks *blanks,
const FcChar8 *dir, const FcChar8 *dir,
FcBool force) FcBool force)
{ {
return FcDirScanConfig (set, dirs, cache, blanks, dir, force, 0); return FcDirScanConfig (set, dirs, blanks, dir, force, 0);
} }
FcBool FcBool

View File

@ -259,7 +259,9 @@ typedef struct _FcStrBuf {
typedef struct _FcCache { typedef struct _FcCache {
int magic; /* FC_CACHE_MAGIC */ int magic; /* FC_CACHE_MAGIC */
int count; /* number of bytes of data in block */ int subdirs; /* number of subdir strings */
off_t pos; /* position of data block in file */
off_t count; /* number of bytes of data in block */
int bank; /* bank ID */ int bank; /* bank ID */
int pattern_count; /* number of FcPatterns */ int pattern_count; /* number of FcPatterns */
int patternelt_count; /* number of FcPatternElts */ int patternelt_count; /* number of FcPatternElts */
@ -323,39 +325,8 @@ typedef struct _FcCaseFold {
#define fc_alignof(type) offsetof (struct { char c; type member; }, member) #define fc_alignof(type) offsetof (struct { char c; type member; }, member)
/*
* The per-user ~/.fonts.cache-<version> file is loaded into
* this data structure. Each directory gets a substructure
* which is validated by comparing the directory timestamp with
* that saved in the cache. When valid, the entire directory cache
* can be immediately loaded without reading the directory. Otherwise,
* the files are checked individually; updated files are loaded into the
* cache which is then rewritten to the users home directory
*/
#define FC_CACHE_MAGIC 0xFC02FC04 #define FC_CACHE_MAGIC 0xFC02FC04
typedef struct _FcGlobalCacheDir FcGlobalCacheDir;
enum FcGCDirState {
FcGCDirDisabled, FcGCDirFileRead, FcGCDirConsumed, FcGCDirUpdated
};
struct _FcGlobalCacheDir {
struct _FcGlobalCacheDir *next;
char *name;
FcCache metadata;
off_t offset;
FcStrSet *subdirs;
void *ent;
enum FcGCDirState state;
};
typedef struct _FcGlobalCache {
FcGlobalCacheDir *dirs;
FcBool updated;
int fd;
} FcGlobalCache;
struct _FcAtomic { struct _FcAtomic {
FcChar8 *file; /* original file name */ FcChar8 *file; /* original file name */
FcChar8 *new; /* temp file name -- write data here */ FcChar8 *new; /* temp file name -- write data here */
@ -445,39 +416,8 @@ typedef struct _FcCharMap FcCharMap;
/* fccache.c */ /* fccache.c */
FcGlobalCache *
FcGlobalCacheCreate (void);
void
FcGlobalCacheDestroy (FcGlobalCache *cache);
FcBool
FcGlobalCacheReadDir (FcFontSet *set,
FcStrSet *dirs,
FcGlobalCache *cache,
const char *dir,
FcConfig *config);
void
FcGlobalCacheLoad (FcGlobalCache *cache,
FcStrSet *staleDirs,
const FcChar8 *cache_file,
FcConfig *config);
FcBool
FcGlobalCacheUpdate (FcGlobalCache *cache,
FcStrSet *dirs,
const char *file,
FcFontSet *set,
FcConfig *config);
FcBool
FcGlobalCacheSave (FcGlobalCache *cache,
const FcChar8 *cache_file,
FcConfig *config);
FcFontSet * FcFontSet *
FcCacheRead (FcConfig *config, FcGlobalCache * cache); FcCacheRead (FcConfig *config);
FcBool FcBool
FcDirCacheWrite (FcFontSet *set, FcStrSet * dirs, const FcChar8 *dir, FcConfig *config); FcDirCacheWrite (FcFontSet *set, FcStrSet * dirs, const FcChar8 *dir, FcConfig *config);
@ -654,7 +594,6 @@ FcFileIsDir (const FcChar8 *file);
FcBool FcBool
FcFileScanConfig (FcFontSet *set, FcFileScanConfig (FcFontSet *set,
FcStrSet *dirs, FcStrSet *dirs,
FcFileCache *cache,
FcBlanks *blanks, FcBlanks *blanks,
const FcChar8 *file, const FcChar8 *file,
FcBool force, FcBool force,
@ -663,7 +602,6 @@ FcFileScanConfig (FcFontSet *set,
FcBool FcBool
FcDirScanConfig (FcFontSet *set, FcDirScanConfig (FcFontSet *set,
FcStrSet *dirs, FcStrSet *dirs,
FcFileCache *cache,
FcBlanks *blanks, FcBlanks *blanks,
const FcChar8 *dir, const FcChar8 *dir,
FcBool force, FcBool force,