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

View File

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

View File

@ -259,7 +259,9 @@ typedef struct _FcStrBuf {
typedef struct _FcCache {
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 pattern_count; /* number of FcPatterns */
int patternelt_count; /* number of FcPatternElts */
@ -323,39 +325,8 @@ typedef struct _FcCaseFold {
#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
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 {
FcChar8 *file; /* original file name */
FcChar8 *new; /* temp file name -- write data here */
@ -445,39 +416,8 @@ typedef struct _FcCharMap FcCharMap;
/* 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 *
FcCacheRead (FcConfig *config, FcGlobalCache * cache);
FcCacheRead (FcConfig *config);
FcBool
FcDirCacheWrite (FcFontSet *set, FcStrSet * dirs, const FcChar8 *dir, FcConfig *config);
@ -654,7 +594,6 @@ FcFileIsDir (const FcChar8 *file);
FcBool
FcFileScanConfig (FcFontSet *set,
FcStrSet *dirs,
FcFileCache *cache,
FcBlanks *blanks,
const FcChar8 *file,
FcBool force,
@ -663,7 +602,6 @@ FcFileScanConfig (FcFontSet *set,
FcBool
FcDirScanConfig (FcFontSet *set,
FcStrSet *dirs,
FcFileCache *cache,
FcBlanks *blanks,
const FcChar8 *dir,
FcBool force,