]> git.wh0rd.org - fontconfig.git/commitdiff
Track dirs containing fonts.cache files referenced from ~/.fonts.cache file
authorKeith Packard <keithp@keithp.com>
Thu, 13 Feb 2003 16:42:38 +0000 (16:42 +0000)
committerKeith Packard <keithp@keithp.com>
Thu, 13 Feb 2003 16:42:38 +0000 (16:42 +0000)
src/fccache.c
src/fcdir.c
src/fcint.h

index 4416412783453ea74e778725e122cc4069855a3e..aff1453d59893c4abf9b43facab7dc85fcfde511 100644 (file)
@@ -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);
index 08334ab2785fddff2820a184406c6b731c6c99c6..6750562c02be75d30bca4ee022dcec20e254d95e 100644 (file)
@@ -177,7 +177,10 @@ FcDirScan (FcFontSet           *set,
         * Check fonts.cache-<version> file
         */
        if (FcDirCacheReadDir (set, dirs, dir))
+       {
+           FcGlobalCacheReferenceSubdir (cache, dir);
            return FcTrue;
+       }
     
        /*
         * Check ~/.fonts.cache-<version> file
index fbdaabd7a771d3394b0e41921650e41e844036e7..f45ba39fc2cd2bc9a53e03ed9af2b657f9ae523e 100644 (file)
@@ -344,6 +344,10 @@ void
 FcGlobalCacheReferenced (FcGlobalCache     *cache,
                         FcGlobalCacheInfo  *info);
 
+void
+FcGlobalCacheReferenceSubdir (FcGlobalCache *cache,
+                             const FcChar8 *dir);
+
 FcGlobalCacheDir *
 FcGlobalCacheDirGet (FcGlobalCache  *cache,
                     const FcChar8  *dir,