]> git.wh0rd.org - fontconfig.git/commitdiff
Compare device numbers as well as inodes. Always normalize directory names
authorPatrick Lam <plam@MIT.EDU>
Sat, 14 Jan 2006 21:23:03 +0000 (21:23 +0000)
committerPatrick Lam <plam@MIT.EDU>
Sat, 14 Jan 2006 21:23:03 +0000 (21:23 +0000)
    before comparing them.
Allocate extra space for appended '/' in directory name.
reviewed by: plam

ChangeLog
fc-cache/fc-cache.c
fc-cat/fc-cat.c
fontconfig/fontconfig.h
src/fccache.c
src/fccfg.c
src/fcdir.c
src/fcint.h

index 266c15b769f5a73005bb342d33af1271a1f7ef47..a09abf5483839a0ecd9ee6cd9571168ff82a9b21 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2006-01-14  Patrick Lam  <plam@mit.edu>
+       * 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  <mfabian@suse.de>
+       reviewed by: plam
+       
+       * fc-cat/fc-cat.c (FcCacheGlobalFileReadAndPrint):
+
+       Allocate extra space for appended '/' in directory name.
+
 2006-01-10  Patrick Lam  <plam@mit.edu>
        * src/fccache.c (FcDirCacheConsume, FcDirCacheOpen,
                         FcDirCacheValid, FcDirCacheHasCurrentArch,
index 6fcf04d444e468356e2db597453e8c10b8a015e0..4900e45e357134faf72632326a80b67378caba70 100644 (file)
@@ -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))
index 419d29ffeabaa6b83cd2060fda1a51d49b6a45c6..3b24302dee0805d61dd079c21030fdfaf71f2bdb 100644 (file)
@@ -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);
index 63434d24774b0a57db3433e715f245cb825eddf6..154959360b3493530b00c6d77984866ff02851e3 100644 (file)
@@ -282,7 +282,7 @@ FcBool
 FcDirCacheHasCurrentArch (const FcChar8 *dir);
 
 FcBool
-FcDirCacheUnlink (const FcChar8 *dir);
+FcDirCacheUnlink (const FcChar8 *dir, FcConfig *config);
 
 /* fcblanks.c */
 FcBlanks *
index 3bf69937d8d978a864a9d5d6166d9cfa188a38e3..b36dbd253087f504a1e3310178e0725b20ac3d58 100644 (file)
@@ -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;
index 8b4494819e430626c18edfc846afb2f21d64be7b..c830444b127d8902c6fc49263a3919f1c03d6cf0 100644 (file)
@@ -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;
index cf4a25be363ae305e2e378365e17c259b49ea0d5..3e6acae6d1495a95782134cc8fc1a636f7a4154d 100644 (file)
@@ -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]);
index 8043e86490bebfe7e6f77b8b2e0840c3c4e4e87a..48f209e58a25835d891de2037e5f6ba826b1d2c1 100644 (file)
@@ -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);