diff --git a/src/fccache.c b/src/fccache.c index fc3ed41..6b8904e 100644 --- a/src/fccache.c +++ b/src/fccache.c @@ -571,6 +571,7 @@ FcCacheDirsValid (FcConfig *config, FcCache *cache) FcBool ret = FcFalse; const FcChar8 *sysroot = FcConfigGetSysRoot (config); FcChar8 *d; + int nfiles; if (!dirs) goto bail; @@ -578,11 +579,11 @@ FcCacheDirsValid (FcConfig *config, FcCache *cache) d = FcStrBuildFilename (sysroot, FcCacheDir (cache), NULL); else d = FcStrdup (FcCacheDir (cache)); - if (!FcDirScanOnly (dirs, d, config)) + if (!FcDirScanOnly (dirs, d, &nfiles, config)) goto bail1; - ret = cache->dirs_count == dirs->num; + ret = cache->dirs_count == dirs->num && nfiles == cache->nfiles; if (FcDebug () & FC_DBG_CACHE) - printf ("%s: cache: %d, fs: %d\n", d, cache->dirs_count, dirs->num); + printf ("%s: cache: %d dir(s) %d file(s), fs: %d dir(s) %d file(s)\n", d, cache->dirs_count, cache->nfiles, dirs->num, nfiles); bail1: FcStrSetDestroy (dirs); @@ -784,7 +785,7 @@ FcDirCacheValid (const FcChar8 *dir) * Build a cache structure from the given contents */ FcCache * -FcDirCacheBuild (FcFontSet *set, const FcChar8 *dir, struct stat *dir_stat, FcStrSet *dirs) +FcDirCacheBuild (FcFontSet *set, const FcChar8 *dir, struct stat *dir_stat, FcStrSet *dirs, int nfiles) { FcSerialize *serialize = FcSerializeCreate (); FcCache *cache; @@ -831,6 +832,7 @@ FcDirCacheBuild (FcFontSet *set, const FcChar8 *dir, struct stat *dir_stat, FcSt cache->version = FC_CACHE_VERSION_NUMBER; cache->size = serialize->size; cache->checksum = (int) dir_stat->st_mtime; + cache->nfiles = nfiles; /* * Serialize directory name @@ -878,13 +880,13 @@ bail1: } FcCache * -FcDirCacheRebuild (FcCache *cache, struct stat *dir_stat, FcStrSet *dirs) +FcDirCacheRebuild (FcCache *cache, struct stat *dir_stat, FcStrSet *dirs, int nfiles) { FcCache *new; FcFontSet *set = FcFontSetDeserialize (FcCacheSet (cache)); const FcChar8 *dir = FcCacheDir (cache); - new = FcDirCacheBuild (set, dir, dir_stat, dirs); + new = FcDirCacheBuild (set, dir, dir_stat, dirs, nfiles); FcFontSetDestroy (set); return new; diff --git a/src/fcdir.c b/src/fcdir.c index 2e7f0dc..2295d67 100644 --- a/src/fcdir.c +++ b/src/fcdir.c @@ -206,7 +206,8 @@ FcDirScanConfig (FcFontSet *set, const FcChar8 *dir, FcBool force, /* XXX unused */ FcConfig *config, - FcBool scanOnly) + FcBool scanOnly, + int *nfiles) { DIR *d; struct dirent *e; @@ -274,6 +275,8 @@ FcDirScanConfig (FcFontSet *set, /* * Scan file files to build font patterns */ + if (nfiles) + *nfiles = files->num; for (i = 0; i < files->num; i++) { if (scanOnly) @@ -309,15 +312,16 @@ FcDirScan (FcFontSet *set, if (cache || !force) return FcFalse; - return FcDirScanConfig (set, dirs, blanks, dir, force, FcConfigGetCurrent (), FcFalse); + return FcDirScanConfig (set, dirs, blanks, dir, force, FcConfigGetCurrent (), FcFalse, NULL); } FcBool FcDirScanOnly (FcStrSet *dirs, const FcChar8 *dir, + int *nfiles, FcConfig *config) { - return FcDirScanConfig (NULL, dirs, NULL, dir, FcTrue, config, FcTrue); + return FcDirScanConfig (NULL, dirs, NULL, dir, FcTrue, config, FcTrue, nfiles); } /* @@ -332,6 +336,7 @@ FcDirCacheScan (const FcChar8 *dir, FcConfig *config) struct stat dir_stat; const FcChar8 *sysroot = FcConfigGetSysRoot (config); FcChar8 *d; + int nfiles = 0; if (sysroot) d = FcStrBuildFilename (sysroot, dir, NULL); @@ -355,13 +360,13 @@ FcDirCacheScan (const FcChar8 *dir, FcConfig *config) /* * Scan the dir */ - if (!FcDirScanConfig (set, dirs, NULL, d, FcTrue, config, FcFalse)) + if (!FcDirScanConfig (set, dirs, NULL, d, FcTrue, config, FcFalse, &nfiles)) goto bail2; /* * Build the cache object */ - cache = FcDirCacheBuild (set, dir, &dir_stat, dirs); + cache = FcDirCacheBuild (set, dir, &dir_stat, dirs, nfiles); if (!cache) goto bail2; @@ -389,6 +394,7 @@ FcDirCacheRescan (const FcChar8 *dir, FcConfig *config) FcStrSet *dirs; const FcChar8 *sysroot = FcConfigGetSysRoot (config); FcChar8 *d = NULL; + int nfiles = 0; cache = FcDirCacheLoad (dir, config, NULL); if (!cache) @@ -407,12 +413,12 @@ FcDirCacheRescan (const FcChar8 *dir, FcConfig *config) /* * Scan the dir */ - if (!FcDirScanConfig (NULL, dirs, NULL, d, FcTrue, config, FcFalse)) + if (!FcDirScanConfig (NULL, dirs, NULL, d, FcTrue, config, FcFalse, &nfiles)) goto bail1; /* * Rebuild the cache object */ - new = FcDirCacheRebuild (cache, &dir_stat, dirs); + new = FcDirCacheRebuild (cache, &dir_stat, dirs, nfiles); if (!new) goto bail1; FcDirCacheUnload (cache); diff --git a/src/fcint.h b/src/fcint.h index ca6f8ef..f269313 100644 --- a/src/fcint.h +++ b/src/fcint.h @@ -369,6 +369,7 @@ struct _FcCache { int dirs_count; /* number of subdir strings */ intptr_t set; /* offset to font set */ int checksum; /* checksum of directory state */ + int nfiles; /* number of font files */ }; #undef FcCacheDir @@ -567,10 +568,10 @@ FcPrivate FcCache * FcDirCacheScan (const FcChar8 *dir, FcConfig *config); FcPrivate FcCache * -FcDirCacheBuild (FcFontSet *set, const FcChar8 *dir, struct stat *dir_stat, FcStrSet *dirs); +FcDirCacheBuild (FcFontSet *set, const FcChar8 *dir, struct stat *dir_stat, FcStrSet *dirs, int nfiles); FcPrivate FcCache * -FcDirCacheRebuild (FcCache *cache, struct stat *dir_stat, FcStrSet *dirs); +FcDirCacheRebuild (FcCache *cache, struct stat *dir_stat, FcStrSet *dirs, int nfiles); FcPrivate FcBool FcDirCacheWrite (FcCache *cache, FcConfig *config); @@ -836,11 +837,13 @@ FcDirScanConfig (FcFontSet *set, const FcChar8 *dir, FcBool force, FcConfig *config, - FcBool scanOnly); + FcBool scanOnly, + int *nfiles); FcPrivate FcBool FcDirScanOnly (FcStrSet *dirs, const FcChar8 *dir, + int *nfiles, FcConfig *config); /* fcfont.c */