]> git.wh0rd.org - fontconfig.git/commitdiff
Warn (and recover) from config file without <cachedir> elements.
authorKeith Packard <keithp@neko.keithp.com>
Sat, 2 Dec 2006 20:14:49 +0000 (12:14 -0800)
committerKeith Packard <keithp@neko.keithp.com>
Sat, 2 Dec 2006 20:14:49 +0000 (12:14 -0800)
When updating from older fontconfig versions, if the config file
is not replaced, it will not contain <cachedir> elements. Lacking these,
fontconfig has no place to store cached font information and cannot operate
reasonably.

Add code to check and see if the loaded configuration has no cache
directories, and if so, warn the user and add both the default system cache
directory and the normal per-user cache directory.

src/fcinit.c

index 7d2311fae2bdb5fc9112f2ea772c5d731f52ec0d..693e0b7b3362eadb712c64a1fe6a065ec6576d55 100644 (file)
@@ -69,6 +69,25 @@ FcInitLoadConfig (void)
        FcConfigDestroy (config);
        return FcInitFallbackConfig ();
     }
+    
+    if (config->cacheDirs && config->cacheDirs->num == 0)
+    {
+       fprintf (stderr,
+                "Fontconfig warning: no <cachedir> elements found. Check configuration.\n");
+       fprintf (stderr,
+                "Fontconfig warning: adding <cachedir>%s</cachedir>\n",
+                FC_CACHEDIR);
+       fprintf (stderr,
+                "Fontconfig warning: adding <cachedir>~/.fontconfig</cachedir>\n");
+       if (!FcConfigAddCacheDir (config, (FcChar8 *) FC_CACHEDIR) ||
+           !FcConfigAddCacheDir (config, (FcChar8 *) "~/.fontconfig"))
+       {
+           fprintf (stderr,
+                    "Fontconfig error: out of memory");
+           FcConfigDestroy (config);
+           return FcInitFallbackConfig ();
+       }
+    }
 
     return config;
 }