]> git.wh0rd.org - fontconfig.git/blobdiff - fc-cache/fc-cache.c
Explicitly add font dirs to config.fontDirs even if they're empty. Set
[fontconfig.git] / fc-cache / fc-cache.c
index 41609a1bffd3b315048849e249a52aa2f5b02b69..6fcf04d444e468356e2db597453e8c10b8a015e0 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * $RCSId: xc/lib/fontconfig/fc-cache/fc-cache.c,v 1.8tsi Exp $
  *
- * Copyright © 2002 Keith Packard
+ * Copyright Â© 2002 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
@@ -141,6 +141,7 @@ scanDirs (FcStrList *list, FcConfig *config, char *program, FcBool force, FcBool
        {
            fprintf (stderr, "Can't create directory set\n");
            ret++;
+           FcFontSetDestroy (set);
            continue;
        }
        
@@ -162,27 +163,35 @@ scanDirs (FcStrList *list, FcConfig *config, char *program, FcBool force, FcBool
                perror ("");
                ret++;
            }
+           FcFontSetDestroy (set);
+           FcStrSetDestroy (subdirs);
            continue;
        }
        if (stat ((char *) dir, &statb) == -1)
        {
            fprintf (stderr, "\"%s\": ", dir);
            perror ("");
+           FcFontSetDestroy (set);
+           FcStrSetDestroy (subdirs);
            ret++;
            continue;
        }
        if (!S_ISDIR (statb.st_mode))
        {
            fprintf (stderr, "\"%s\": not a directory, skipping\n", dir);
+           FcFontSetDestroy (set);
+           FcStrSetDestroy (subdirs);
            continue;
        }
-       if (!FcDirScan (set, subdirs, 0, FcConfigGetBlanks (config), dir, force))
+       if (!FcDirScanConfig (set, subdirs, 0, FcConfigGetBlanks (config), dir, force, config))
        {
            fprintf (stderr, "\"%s\": error scanning\n", dir);
+           FcFontSetDestroy (set);
+           FcStrSetDestroy (subdirs);
            ret++;
            continue;
        }
-       if (!force && FcDirCacheValid (dir))
+       if (!force && FcDirCacheValid (dir) && FcDirCacheHasCurrentArch (dir))
        {
            if (verbose)
                printf ("skipping, %d fonts, %d dirs\n",
@@ -193,14 +202,22 @@ scanDirs (FcStrList *list, FcConfig *config, char *program, FcBool force, FcBool
            if (verbose)
                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);
+                if (!ret)
+                    fprintf (stderr, "Caches are currently saved to \"%s\"\n", PKGCACHEDIR);
+               fprintf (stderr, "Can't save cache for \"%s\"\n", dir);
                ret++;
            }
        }
        FcFontSetDestroy (set);
        sublist = FcStrListCreate (subdirs);
+       FcStrSetDestroy (subdirs);
        if (!sublist)
        {
            fprintf (stderr, "Can't create subdir list in \"%s\"\n", dir);
@@ -208,7 +225,6 @@ scanDirs (FcStrList *list, FcConfig *config, char *program, FcBool force, FcBool
            continue;
        }
        ret += scanDirs (sublist, config, program, force, verbose);
-       FcStrSetDestroy (subdirs);
     }
     FcStrListDone (list);
     return ret;
@@ -265,6 +281,8 @@ main (int argc, char **argv)
        fprintf (stderr, "%s: Can't init font config library\n", argv[0]);
        return 1;
     }
+    FcConfigSetCurrent (config);
+
     if (argv[i])
     {
        dirs = FcStrSetCreate ();
@@ -296,6 +314,7 @@ main (int argc, char **argv)
      * sleep(3) can't be interrupted by a signal here -- this isn't in the
      * library, and there aren't any signals flying around here.
      */
+    FcConfigDestroy (config);
     sleep (2);
     if (verbose)
        printf ("%s: %s\n", argv[0], ret ? "failed" : "succeeded");