From 8a0b0ed6d01e4e20ab6727211fe5823395a9b4c4 Mon Sep 17 00:00:00 2001 From: Patrick Lam Date: Sat, 14 Jan 2006 21:23:03 +0000 Subject: [PATCH] Compare device numbers as well as inodes. Always normalize directory names before comparing them. Allocate extra space for appended '/' in directory name. reviewed by: plam --- ChangeLog | 19 +++++++++++++++++++ fc-cache/fc-cache.c | 2 +- fc-cat/fc-cat.c | 6 +++++- fontconfig/fontconfig.h | 2 +- src/fccache.c | 19 ++++++++++++++----- src/fccfg.c | 7 ++++--- src/fcdir.c | 2 +- src/fcint.h | 6 ++++-- 8 files changed, 49 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 266c15b..a09abf5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2006-01-14 Patrick Lam + * fc-cache/fc-cache.c (scanDirs): + * fontconfig/fontconfig.h: + * src/fccache.c (FcGlobalCacheReadDir, FcGlobalCacheUpdate, + FcGlobalCacheSave, FcDirCacheUnlink, FcDirCacheOpen): + * src/fccfg.c (FcConfigBuildFonts, FcConfigNormalizeFontDir): + * src/fcdir.c (FcDirScanConfig): + * src/fcint.h: + + Compare device numbers as well as inodes. + Always normalize directory names before comparing them. + +2006-01-11 Mike Fabian + reviewed by: plam + + * fc-cat/fc-cat.c (FcCacheGlobalFileReadAndPrint): + + Allocate extra space for appended '/' in directory name. + 2006-01-10 Patrick Lam * src/fccache.c (FcDirCacheConsume, FcDirCacheOpen, FcDirCacheValid, FcDirCacheHasCurrentArch, diff --git a/fc-cache/fc-cache.c b/fc-cache/fc-cache.c index 6fcf04d..4900e45 100644 --- a/fc-cache/fc-cache.c +++ b/fc-cache/fc-cache.c @@ -204,7 +204,7 @@ scanDirs (FcStrList *list, FcConfig *config, char *program, FcBool force, FcBool set->nfont, nsubdirs (subdirs)); if (!FcDirCacheValid (dir)) - if (!FcDirCacheUnlink (dir)) + if (!FcDirCacheUnlink (dir, config)) ret++; if (!FcDirSave (set, subdirs, dir)) diff --git a/fc-cat/fc-cat.c b/fc-cat/fc-cat.c index 419d29f..3b24302 100644 --- a/fc-cat/fc-cat.c +++ b/fc-cat/fc-cat.c @@ -205,7 +205,11 @@ FcCacheGlobalFileReadAndPrint (FcFontSet * set, FcStrSet *dirs, char *cache_file if (!FcDirCacheConsume (fd, name_buf, set, 0)) goto bail1; - dir = strdup(name_buf); + dir = malloc (strlen (name_buf) + 2); + if (!dir) + goto bail1; + + strcpy (dir, name_buf); strcat (dir, "/"); FcCachePrintSet (set, dirs, dir); diff --git a/fontconfig/fontconfig.h b/fontconfig/fontconfig.h index 63434d2..1549593 100644 --- a/fontconfig/fontconfig.h +++ b/fontconfig/fontconfig.h @@ -282,7 +282,7 @@ FcBool FcDirCacheHasCurrentArch (const FcChar8 *dir); FcBool -FcDirCacheUnlink (const FcChar8 *dir); +FcDirCacheUnlink (const FcChar8 *dir, FcConfig *config); /* fcblanks.c */ FcBlanks * diff --git a/src/fccache.c b/src/fccache.c index 3bf6993..b36dbd2 100644 --- a/src/fccache.c +++ b/src/fccache.c @@ -304,6 +304,7 @@ FcGlobalCacheReadDir (FcFontSet *set, FcStrSet *dirs, FcGlobalCache * cache, con if (cache->fd == -1) return FcFalse; + dir = (char *)FcConfigNormalizeFontDir (config, (FcChar8 *)dir); for (d = cache->dirs; d; d = d->next) { if (strncmp (d->name, dir, strlen(dir)) == 0) @@ -322,10 +323,12 @@ FcGlobalCacheReadDir (FcFontSet *set, FcStrSet *dirs, FcGlobalCache * cache, con FcBool FcGlobalCacheUpdate (FcGlobalCache *cache, const char *name, - FcFontSet *set) + FcFontSet *set, + FcConfig *config) { FcGlobalCacheDir * d; + name = (char *)FcConfigNormalizeFontDir (config, (FcChar8 *)name); for (d = cache->dirs; d; d = d->next) { if (strcmp(d->name, name) == 0) @@ -351,7 +354,8 @@ FcGlobalCacheUpdate (FcGlobalCache *cache, FcBool FcGlobalCacheSave (FcGlobalCache *cache, - const FcChar8 *cache_file) + const FcChar8 *cache_file, + FcConfig *config) { int fd, fd_orig; FcGlobalCacheDir *dir; @@ -425,7 +429,9 @@ FcGlobalCacheSave (FcGlobalCache *cache, { if (dir->name) { - FcCacheWriteString (fd, dir->name); + const char * d = (const char *)FcConfigNormalizeFontDir (config, (const FcChar8 *)dir->name); + + FcCacheWriteString (fd, d); write (fd, &dir->metadata, sizeof(FcCache)); lseek (fd, FcCacheNextOffset (lseek(fd, 0, SEEK_CUR)), SEEK_SET); write (fd, dir->ent, dir->metadata.count); @@ -649,14 +655,16 @@ FcDirCacheHasCurrentArch (const FcChar8 *dir) } FcBool -FcDirCacheUnlink (const FcChar8 *dir) +FcDirCacheUnlink (const FcChar8 *dir, FcConfig *config) { - char *cache_file = (char *)FcStrPlus (dir, (FcChar8 *) "/" FC_DIR_CACHE_FILE); + char *cache_file; char *cache_hashed; int fd, collisions; struct stat cache_stat; char name_buf[FC_MAX_FILE_LEN]; + dir = FcConfigNormalizeFontDir (config, dir); + cache_file = (char *)FcStrPlus (dir, (FcChar8 *) "/" FC_DIR_CACHE_FILE); if (!cache_file) return FcFalse; @@ -878,6 +886,7 @@ FcDirCacheOpen (const FcChar8 *dir) if (stat ((char *)dir, &dir_stat) == -1) return -1; + found = FcFalse; do { struct stat c; diff --git a/src/fccfg.c b/src/fccfg.c index 8b44948..c830444 100644 --- a/src/fccfg.c +++ b/src/fccfg.c @@ -325,7 +325,7 @@ FcConfigBuildFonts (FcConfig *config) FcFontSetPrint (fonts); if (config->cache) - FcGlobalCacheSave (cache, config->cache); + FcGlobalCacheSave (cache, config->cache, config); FcGlobalCacheDestroy (cache); FcStrSetDestroy (oldDirs); @@ -394,18 +394,19 @@ FcConfigNormalizeFontDir (FcConfig *config, { /* If this is a bottleneck, we can cache the fontDir inodes. */ ino_t di; + dev_t dd; int n; struct stat s; if (stat ((char *)d, &s) == -1) return 0; - di = s.st_ino; + di = s.st_ino; dd = s.st_dev; for (n = 0; n < config->fontDirs->num; n++) { if (stat ((char *)config->fontDirs->strs[n], &s) == -1) continue; - if (di == s.st_ino) + if (di == s.st_ino && dd == s.st_dev) return config->fontDirs->strs[n]; } return 0; diff --git a/src/fcdir.c b/src/fcdir.c index cf4a25b..3e6acae 100644 --- a/src/fcdir.c +++ b/src/fcdir.c @@ -188,7 +188,7 @@ FcDirScanConfig (FcFontSet *set, * add the cache entry */ if (ret && cache) - FcGlobalCacheUpdate (cache, (char *)dir, tmpSet); + FcGlobalCacheUpdate (cache, (char *)dir, tmpSet, config); for (i = 0; i < tmpSet->nfont; i++) FcFontSetAdd (set, tmpSet->fonts[i]); diff --git a/src/fcint.h b/src/fcint.h index 8043e86..48f209e 100644 --- a/src/fcint.h +++ b/src/fcint.h @@ -448,11 +448,13 @@ FcGlobalCacheLoad (FcGlobalCache *cache, FcBool FcGlobalCacheUpdate (FcGlobalCache *cache, const char *file, - FcFontSet *set); + FcFontSet *set, + FcConfig *config); FcBool FcGlobalCacheSave (FcGlobalCache *cache, - const FcChar8 *cache_file); + const FcChar8 *cache_file, + FcConfig *config); FcFontSet * FcCacheRead (FcConfig *config, FcGlobalCache * cache); -- 2.39.5