From 55c8fa4f08b86f4e9af97920a61943f5facd7822 Mon Sep 17 00:00:00 2001 From: Patrick Lam Date: Wed, 5 Oct 2005 00:34:52 +0000 Subject: [PATCH] Add new API which unlinks directory caches and checks dir caches for existence of appropriate sections. Fix fc-cache to unlink stale cache files and save directory caches that lack relevant sections. --- ChangeLog | 11 +++++++++++ fc-cache/fc-cache.c | 6 +++++- fontconfig/fontconfig.h | 6 ++++++ src/fccache.c | 44 +++++++++++++++++++++++++++++++---------- 4 files changed, 56 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index d85f2b2..b7cfb91 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2005-10-04 Patrick Lam + * src/fccache.c (FcDirCacheValid, FcDirCacheUnlink, + FcDirCacheHasCurrentArch): + * fc-cache/fc-cache.c (scanDirs): + * fontconfig/fontconfig.h: + + Add new API which unlinks directory caches and checks dir caches + for existence of appropriate sections. Fix fc-cache to unlink + stale cache files and save directory caches that lack relevant + sections. + 2005-10-03 Patrick Lam * src/fccache.c (FcDirCacheValid): diff --git a/fc-cache/fc-cache.c b/fc-cache/fc-cache.c index 20c7c95..388baa7 100644 --- a/fc-cache/fc-cache.c +++ b/fc-cache/fc-cache.c @@ -191,7 +191,7 @@ scanDirs (FcStrList *list, FcConfig *config, char *program, FcBool force, FcBool ret++; continue; } - if (!force && FcDirCacheValid (dir)) + if (!force && FcDirCacheValid (dir) && FcDirCacheHasCurrentArch (dir)) { if (verbose) printf ("skipping, %d fonts, %d dirs\n", @@ -203,6 +203,10 @@ scanDirs (FcStrList *list, FcConfig *config, char *program, FcBool force, FcBool printf ("caching, %d fonts, %d dirs\n", set->nfont, nsubdirs (subdirs)); + if (!FcDirCacheValid (dir)) + if (!FcDirCacheUnlink (dir)) + ret++; + if (!FcDirSave (set, subdirs, dir)) { fprintf (stderr, "Can't save cache in \"%s\"\n", dir); diff --git a/fontconfig/fontconfig.h b/fontconfig/fontconfig.h index 34e7b8b..2ffcb24 100644 --- a/fontconfig/fontconfig.h +++ b/fontconfig/fontconfig.h @@ -273,6 +273,12 @@ _FCFUNCPROTOBEGIN FcBool FcDirCacheValid (const FcChar8 *cache_file); +FcBool +FcDirCacheHasCurrentArch (const FcChar8 *dir); + +FcBool +FcDirCacheUnlink (const FcChar8 *dir); + /* fcblanks.c */ FcBlanks * FcBlanksCreate (void); diff --git a/src/fccache.c b/src/fccache.c index 7ff9fc6..43e45af 100644 --- a/src/fccache.c +++ b/src/fccache.c @@ -517,14 +517,12 @@ FcCacheCopyOld (int fd, int fd_orig, off_t start) return FcFalse; } +/* Does not check that the cache has the appropriate arch section. */ FcBool FcDirCacheValid (const FcChar8 *dir) { FcChar8 *cache_file = FcStrPlus (dir, (FcChar8 *) "/" FC_DIR_CACHE_FILE); struct stat file_stat, dir_stat; - int fd; - off_t current_arch_start; - char *current_arch_machine_name; if (stat ((char *) dir, &dir_stat) < 0) { @@ -537,8 +535,28 @@ FcDirCacheValid (const FcChar8 *dir) return FcFalse; } + FcStrFree (cache_file); + /* + * If the directory has been modified more recently than + * the cache file, the cache is not valid + */ + if (dir_stat.st_mtime - file_stat.st_mtime > 0) + return FcFalse; + return FcTrue; +} + +/* Assumes that the cache file in 'dir' exists. + * Checks that the cache has the appropriate arch section. */ +FcBool +FcDirCacheHasCurrentArch (const FcChar8 *dir) +{ + FcChar8 *cache_file = FcStrPlus (dir, (FcChar8 *) "/" FC_DIR_CACHE_FILE); + int fd; + off_t current_arch_start; + char *current_arch_machine_name; + current_arch_machine_name = FcCacheMachineSignature(); - fd = open(cache_file, O_RDONLY); + fd = open ((char *)cache_file, O_RDONLY); if (fd == -1) return FcFalse; @@ -547,14 +565,20 @@ FcDirCacheValid (const FcChar8 *dir) if (current_arch_start < 0) return FcFalse; + + return FcTrue; +} - FcStrFree (cache_file); - /* - * If the directory has been modified more recently than - * the cache file, the cache is not valid - */ - if (dir_stat.st_mtime - file_stat.st_mtime > 0) +FcBool +FcDirCacheUnlink (const FcChar8 *dir) +{ + FcChar8 *cache_file = FcStrPlus (dir, (FcChar8 *) "/" FC_DIR_CACHE_FILE); + + if (!unlink ((char *)cache_file)) return FcFalse; + + FcStrFree (cache_file); + return FcTrue; } -- 2.39.5