From c4ab52dcb5d016d18fc73a8577daeb6938fb9e84 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 13 Feb 2003 16:42:38 +0000 Subject: [PATCH] Track dirs containing fonts.cache files referenced from ~/.fonts.cache file --- src/fccache.c | 45 ++++++++++++++++++++++++++++++++++++++------- src/fcdir.c | 3 +++ src/fcint.h | 4 ++++ 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/fccache.c b/src/fccache.c index 4416412..aff1453 100644 --- a/src/fccache.c +++ b/src/fccache.c @@ -427,13 +427,29 @@ static FcGlobalCacheInfo * FcGlobalCacheDirAdd (FcGlobalCache *cache, const FcChar8 *dir, time_t time, - FcBool replace) + FcBool replace, + FcBool create_missing) { FcGlobalCacheDir *d; FcFilePathInfo i; FcGlobalCacheSubdir *subdir; FcGlobalCacheDir *parent; + i = FcFilePathInfoGet (dir); + parent = FcGlobalCacheDirGet (cache, i.dir, i.dir_len, create_missing); + /* + * Tricky here -- directories containing fonts.cache-1 files + * need entries only when the parent doesn't have a cache file. + * That is, when the parent already exists in the cache, is + * referenced and has a "real" timestamp. The time of 0 is + * special and marks directories which got stuck in the + * global cache for this very reason. Yes, it could + * use a separate boolean field, and probably should. + */ + if (!parent || (!create_missing && + (!parent->info.referenced || + (parent->info.time == 0)))) + return 0; /* * Add this directory to the cache */ @@ -441,13 +457,9 @@ FcGlobalCacheDirAdd (FcGlobalCache *cache, if (!d) return 0; d->info.time = time; - i = FcFilePathInfoGet (dir); /* * Add this directory to the subdirectory list of the parent */ - parent = FcGlobalCacheDirGet (cache, i.dir, i.dir_len, FcTrue); - if (!parent) - return 0; subdir = malloc (sizeof (FcGlobalCacheSubdir)); if (!subdir) return 0; @@ -484,6 +496,25 @@ FcGlobalCacheDirDestroy (FcGlobalCacheDir *d) free (d); } +/* + * If the parent is in the global cache and referenced, add + * an entry for 'dir' to the global cache. This is used + * for directories with fonts.cache files + */ + +void +FcGlobalCacheReferenceSubdir (FcGlobalCache *cache, + const FcChar8 *dir) +{ + FcGlobalCacheInfo *info; + info = FcGlobalCacheDirAdd (cache, dir, 0, FcFalse, FcFalse); + if (info && !info->referenced) + { + info->referenced = FcTrue; + cache->referenced++; + } +} + /* * Check to see if the global cache contains valid data for 'dir'. * If so, scan the global cache for files and directories in 'dir'. @@ -739,7 +770,7 @@ FcGlobalCacheLoad (FcGlobalCache *cache, if (FcDebug () & FC_DBG_CACHEV) printf ("FcGlobalCacheLoad \"%s\" \"%20.20s\"\n", file, name); if (!FcStrCmp (name, FC_FONT_FILE_DIR)) - info = FcGlobalCacheDirAdd (cache, file, time, FcFalse); + info = FcGlobalCacheDirAdd (cache, file, time, FcFalse, FcTrue); else info = FcGlobalCacheFileAdd (cache, file, id, time, name, FcFalse); if (!info) @@ -779,7 +810,7 @@ FcGlobalCacheUpdate (FcGlobalCache *cache, return FcFalse; if (S_ISDIR (statb.st_mode)) info = FcGlobalCacheDirAdd (cache, file, statb.st_mtime, - FcTrue); + FcTrue, FcTrue); else info = FcGlobalCacheFileAdd (cache, file, id, statb.st_mtime, name, FcTrue); diff --git a/src/fcdir.c b/src/fcdir.c index 08334ab..6750562 100644 --- a/src/fcdir.c +++ b/src/fcdir.c @@ -177,7 +177,10 @@ FcDirScan (FcFontSet *set, * Check fonts.cache- file */ if (FcDirCacheReadDir (set, dirs, dir)) + { + FcGlobalCacheReferenceSubdir (cache, dir); return FcTrue; + } /* * Check ~/.fonts.cache- file diff --git a/src/fcint.h b/src/fcint.h index fbdaabd..f45ba39 100644 --- a/src/fcint.h +++ b/src/fcint.h @@ -344,6 +344,10 @@ void FcGlobalCacheReferenced (FcGlobalCache *cache, FcGlobalCacheInfo *info); +void +FcGlobalCacheReferenceSubdir (FcGlobalCache *cache, + const FcChar8 *dir); + FcGlobalCacheDir * FcGlobalCacheDirGet (FcGlobalCache *cache, const FcChar8 *dir, -- 2.39.5