]> git.wh0rd.org - fontconfig.git/blobdiff - src/fcdir.c
Add test for validity of directory caches that somehow got lost (reported
[fontconfig.git] / src / fcdir.c
index 5c9646f30a80b5029d8818cacdde766437ac9639..5452b60ca6f91daf2c6da51610faac751e7fbb29 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * $RCSId: xc/lib/fontconfig/src/fcdir.c,v 1.9 2002/08/31 22:17:32 keithp Exp $
  *
- * Copyright © 2000 Keith Packard
+ * Copyright Â© 2000 Keith Packard
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
@@ -45,14 +45,10 @@ FcFileScanConfig (FcFontSet *set,
                  FcConfig      *config)
 {
     int                        id;
-    FcChar8            *name;
     FcPattern          *font;
     FcBool             ret = FcTrue;
     FcBool             isDir;
     int                        count = 0;
-    FcGlobalCacheFile  *cache_file;
-    FcGlobalCacheDir   *cache_dir;
-    FcBool             need_scan;
     
     if (config && !FcConfigAcceptFilename (config, file))
        return FcTrue;
@@ -62,81 +58,23 @@ FcFileScanConfig (FcFontSet *set,
     id = 0;
     do
     {
-       need_scan = FcTrue;
        font = 0;
        /*
-        * Check the cache
+        * Nothing in the cache, scan the file
         */
-       if (cache)
+       if (FcDebug () & FC_DBG_SCAN)
        {
-           if ((cache_file = FcGlobalCacheFileGet (cache, file, id, &count)))
-           {
-               /*
-                * Found a cache entry for the file
-                */
-               if (FcGlobalCacheCheckTime (file, &cache_file->info))
-               {
-                   name = cache_file->name;
-                   need_scan = FcFalse;
-                   FcGlobalCacheReferenced (cache, &cache_file->info);
-                   /* "." means the file doesn't contain a font */
-                   if (FcStrCmp (name, FC_FONT_FILE_INVALID) != 0)
-                   {
-                       font = FcNameParse (name);
-                       if (font)
-                           if (!FcPatternAddString (font, FC_FILE, file))
-                               ret = FcFalse;
-                   }
-               }
-           }
-           else if ((cache_dir = FcGlobalCacheDirGet (cache, file,
-                                                      strlen ((const char *) file),
-                                                      FcFalse)))
-           {
-               if (FcGlobalCacheCheckTime (cache_dir->info.file, 
-                                           &cache_dir->info))
-               {
-                   font = 0;
-                   need_scan = FcFalse;
-                   FcGlobalCacheReferenced (cache, &cache_dir->info);
-                   if (!FcStrSetAdd (dirs, file))
-                       ret = FcFalse;
-               }
-           }
+           printf ("\tScanning file %s...", file);
+           fflush (stdout);
        }
-       /*
-        * Nothing in the cache, scan the file
-        */
-       if (need_scan)
+       font = FcFreeTypeQuery (file, id, blanks, &count);
+       if (FcDebug () & FC_DBG_SCAN)
+           printf ("done\n");
+       isDir = FcFalse;
+       if (!font && FcFileIsDir (file))
        {
-           if (FcDebug () & FC_DBG_SCAN)
-           {
-               printf ("\tScanning file %s...", file);
-               fflush (stdout);
-           }
-           font = FcFreeTypeQuery (file, id, blanks, &count);
-           if (FcDebug () & FC_DBG_SCAN)
-               printf ("done\n");
-           isDir = FcFalse;
-           if (!font && FcFileIsDir (file))
-           {
-               isDir = FcTrue;
-               ret = FcStrSetAdd (dirs, file);
-           }
-           /*
-            * Update the cache
-            */
-           if (cache && font)
-           {
-               FcChar8 *unparse;
-
-               unparse = FcNameUnparse (font);
-               if (unparse)
-               {
-                   (void) FcGlobalCacheUpdate (cache, file, id, unparse);
-                   FcStrFree (unparse);
-               }
-           }
+           isDir = FcTrue;
+           ret = FcStrSetAdd (dirs, file);
        }
        /*
         * Add the font
@@ -150,6 +88,8 @@ FcFileScanConfig (FcFontSet  *set,
                ret = FcFalse;
            }
        }
+       else if (font)
+           FcPatternDestroy (font);
        id++;
     } while (font && ret && id < count);
     return ret;
@@ -185,26 +125,21 @@ FcDirScanConfig (FcFontSet        *set,
     FcChar8            *file;
     FcChar8            *base;
     FcBool             ret = FcTrue;
+    FcFontSet          *tmpSet;
+    int                        i;
 
     if (config && !FcConfigAcceptFilename (config, dir))
        return FcTrue;
 
     if (!force)
     {
-       /*
-        * Check fonts.cache-<version> file
-        */
-       if (FcDirCacheReadDir (set, dirs, dir, config))
-       {
-           if (cache)
-               FcGlobalCacheReferenceSubdir (cache, dir);
-           return FcTrue;
-       }
-    
        /*
         * Check ~/.fonts.cache-<version> file
         */
-       if (cache && FcGlobalCacheScanDir (set, dirs, cache, dir, config))
+       if (cache && FcGlobalCacheReadDir (set, dirs, cache, (char *)dir, config))
+           return FcTrue;
+
+       if (FcDirCacheValid (dir) && FcDirCacheRead (set, dirs, dir))
            return FcTrue;
     }
     
@@ -221,7 +156,6 @@ FcDirScanConfig (FcFontSet  *set,
        printf ("\tScanning dir %s\n", dir);
        
     d = opendir ((char *) dir);
-    
     if (!d)
     {
        free (file);
@@ -230,12 +164,20 @@ FcDirScanConfig (FcFontSet        *set,
            return FcTrue;
        return FcFalse;
     }
+
+    tmpSet = FcFontSetCreate();
+    if (!tmpSet)
+    {  
+       free (file);
+       return FcFalse;
+    }
+
     while (ret && (e = readdir (d)))
     {
        if (e->d_name[0] != '.' && strlen (e->d_name) < FC_MAX_FILE_LEN)
        {
            strcpy ((char *) base, (char *) e->d_name);
-           ret = FcFileScanConfig (set, dirs, cache, blanks, file, force, config);
+           ret = FcFileScanConfig (tmpSet, dirs, cache, blanks, file, force, config);
        }
     }
     free (file);
@@ -245,7 +187,18 @@ FcDirScanConfig (FcFontSet *set,
      * add the cache entry 
      */
     if (ret && cache)
-       FcGlobalCacheUpdate (cache, dir, 0, 0);
+       FcGlobalCacheUpdate (cache, (char *)dir, tmpSet);
+
+    for (i = 0; i < tmpSet->nfont; i++)
+       FcFontSetAdd (set, tmpSet->fonts[i]);
+
+    if (tmpSet->fonts)
+    {
+       FcMemFree (FC_MEM_FONTPTR, tmpSet->sfont * sizeof (FcPattern *));
+       free (tmpSet->fonts);
+    }
+    FcMemFree (FC_MEM_FONTSET, sizeof (FcFontSet));
+    free (tmpSet);
        
     return ret;
 }
@@ -262,7 +215,7 @@ FcDirScan (FcFontSet            *set,
 }
 
 FcBool
-FcDirSave (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir)
+FcDirSave (FcFontSet *set, FcStrSet * dirs, const FcChar8 *dir)
 {
-    return FcDirCacheWriteDir (set, dirs, dir);
+    return FcDirCacheWrite (set, dirs, dir);
 }