[Fontconfig] fontconfig: Branch 'master'

Akira TAGOH tagoh at kemper.freedesktop.org
Tue Jun 17 04:13:01 PDT 2014


 fc-cache/fc-cache.c |   10 +++---
 src/fccache.c       |   76 ++++++++++++++++++++++++++++++++++--------------
 src/fccfg.c         |    2 -
 src/fcdir.c         |   82 +++++++++++++++++++++++++++++++++++++++++++++-------
 src/fcinit.c        |   17 ++++++++--
 src/fcint.h         |    3 +
 src/fcxml.c         |   12 +++++--
 7 files changed, 158 insertions(+), 44 deletions(-)

New commits:
commit d17f556153fbaf8fe57fdb4fc1f0efa4313f0ecf
Author: Akira TAGOH <akira at tagoh.org>
Date:   Tue Jun 17 20:08:24 2014 +0900

    Read the config files and fonts on the sysroot when --sysroot is given to fc-cache
    
    Fix for e96d7760886a3781a46b3271c76af99e15cb0146
    
    https://bugs.freedesktop.org/show_bug.cgi?id=59456

diff --git a/fc-cache/fc-cache.c b/fc-cache/fc-cache.c
index 90ebad3..406ac6a 100644
--- a/fc-cache/fc-cache.c
+++ b/fc-cache/fc-cache.c
@@ -128,7 +128,8 @@ scanDirs (FcStrList *list, FcConfig *config, FcBool force, FcBool really_force,
     struct stat	    statb;
     FcBool	    was_valid;
     int		    i;
-    
+    const FcChar8   *sysroot = FcConfigGetSysRoot (config);
+
     /*
      * Now scan all of the directories into separate databases
      * and write out the results
@@ -138,9 +139,10 @@ scanDirs (FcStrList *list, FcConfig *config, FcBool force, FcBool really_force,
 	if (verbose)
 	{
 	    if (!recursive)
-		printf ("Re-scanning %s: ", dir);
-	    else
-		printf ("%s: ", dir);
+		printf ("Re-scanning ");
+	    if (sysroot)
+		printf ("[%s]", sysroot);
+	    printf ("%s: ", dir);
 	    fflush (stdout);
 	}
 	
diff --git a/src/fccache.c b/src/fccache.c
index 085bd72..25538bd 100644
--- a/src/fccache.c
+++ b/src/fccache.c
@@ -177,19 +177,28 @@ FcDirCacheOpenFile (const FcChar8 *cache_file, struct stat *file_stat)
  */
 static FcBool
 FcDirCacheProcess (FcConfig *config, const FcChar8 *dir,
-		   FcBool (*callback) (int fd, struct stat *fd_stat,
+		   FcBool (*callback) (FcConfig *config, int fd, struct stat *fd_stat,
 				       struct stat *dir_stat, void *closure),
 		   void *closure, FcChar8 **cache_file_ret)
 {
     int		fd = -1;
     FcChar8	cache_base[CACHEBASE_LEN];
     FcStrList	*list;
-    FcChar8	*cache_dir;
+    FcChar8	*cache_dir, *d;
     struct stat file_stat, dir_stat;
     FcBool	ret = FcFalse;
+    const FcChar8 *sysroot = FcConfigGetSysRoot (config);
 
-    if (FcStatChecksum (dir, &dir_stat) < 0)
+    if (sysroot)
+	d = FcStrBuildFilename (sysroot, dir, NULL);
+    else
+	d = FcStrdup (dir);
+    if (FcStatChecksum (d, &dir_stat) < 0)
+    {
+	FcStrFree (d);
         return FcFalse;
+    }
+    FcStrFree (d);
 
     FcDirCacheBasename (dir, cache_base);
 
@@ -199,7 +208,6 @@ FcDirCacheProcess (FcConfig *config, const FcChar8 *dir,
 	
     while ((cache_dir = FcStrListNext (list)))
     {
-	const FcChar8 *sysroot = FcConfigGetSysRoot (config);
         FcChar8	*cache_hashed;
 
 	if (sysroot)
@@ -210,7 +218,7 @@ FcDirCacheProcess (FcConfig *config, const FcChar8 *dir,
 	    break;
         fd = FcDirCacheOpenFile (cache_hashed, &file_stat);
         if (fd >= 0) {
-	    ret = (*callback) (fd, &file_stat, &dir_stat, closure);
+	    ret = (*callback) (config, fd, &file_stat, &dir_stat, closure);
 	    close (fd);
 	    if (ret)
 	    {
@@ -529,14 +537,25 @@ FcCacheFini (void)
 }
 
 static FcBool
-FcCacheTimeValid (FcCache *cache, struct stat *dir_stat)
+FcCacheTimeValid (FcConfig *config, FcCache *cache, struct stat *dir_stat)
 {
     struct stat	dir_static;
 
     if (!dir_stat)
     {
-	if (FcStatChecksum (FcCacheDir (cache), &dir_static) < 0)
+	const FcChar8 *sysroot = FcConfigGetSysRoot (config);
+	FcChar8 *d;
+
+	if (sysroot)
+	    d = FcStrBuildFilename (sysroot, FcCacheDir (cache), NULL);
+	else
+	    d = FcStrdup (FcCacheDir (cache));
+	if (FcStatChecksum (d, &dir_static) < 0)
+	{
+	    FcStrFree (d);
 	    return FcFalse;
+	}
+	FcStrFree (d);
 	dir_stat = &dir_static;
     }
     if (FcDebug () & FC_DBG_CACHE)
@@ -546,21 +565,28 @@ FcCacheTimeValid (FcCache *cache, struct stat *dir_stat)
 }
 
 static FcBool
-FcCacheDirsValid (FcCache *cache)
+FcCacheDirsValid (FcConfig *config, FcCache *cache)
 {
     FcStrSet *dirs = FcStrSetCreate ();
     FcBool ret = FcFalse;
+    const FcChar8 *sysroot = FcConfigGetSysRoot (config);
+    FcChar8 *d;
 
     if (!dirs)
 	goto bail;
-    if (!FcDirScanOnly (dirs, FcCacheDir (cache)))
+    if (sysroot)
+	d = FcStrBuildFilename (sysroot, FcCacheDir (cache), NULL);
+    else
+	d = FcStrdup (FcCacheDir (cache));
+    if (!FcDirScanOnly (dirs, d, config))
 	goto bail1;
     ret = cache->dirs_count == dirs->num;
     if (FcDebug () & FC_DBG_CACHE)
-	printf ("%s: cache: %d, fs: %d\n", FcCacheDir (cache), cache->dirs_count, dirs->num);
+	printf ("%s: cache: %d, fs: %d\n", d, cache->dirs_count, dirs->num);
 
 bail1:
     FcStrSetDestroy (dirs);
+    FcStrFree (d);
 bail:
     return ret;
 }
@@ -569,7 +595,7 @@ bail:
  * Map a cache file into memory
  */
 static FcCache *
-FcDirCacheMapFd (int fd, struct stat *fd_stat, struct stat *dir_stat)
+FcDirCacheMapFd (FcConfig *config, int fd, struct stat *fd_stat, struct stat *dir_stat)
 {
     FcCache	*cache;
     FcBool	allocated = FcFalse;
@@ -579,8 +605,8 @@ FcDirCacheMapFd (int fd, struct stat *fd_stat, struct stat *dir_stat)
     cache = FcCacheFindByStat (fd_stat);
     if (cache)
     {
-	if (FcCacheTimeValid (cache, dir_stat) &&
-	    FcCacheDirsValid (cache))
+	if (FcCacheTimeValid (config, cache, dir_stat) &&
+	    FcCacheDirsValid (config, cache))
 	    return cache;
 	FcDirCacheUnload (cache);
 	cache = NULL;
@@ -631,8 +657,8 @@ FcDirCacheMapFd (int fd, struct stat *fd_stat, struct stat *dir_stat)
     if (cache->magic != FC_CACHE_MAGIC_MMAP ||
 	cache->version < FC_CACHE_CONTENT_VERSION ||
 	cache->size != (intptr_t) fd_stat->st_size ||
-	!FcCacheTimeValid (cache, dir_stat) ||
-	!FcCacheDirsValid (cache) ||
+	!FcCacheTimeValid (config, cache, dir_stat) ||
+	!FcCacheDirsValid (config, cache) ||
 	!FcCacheInsert (cache, fd_stat))
     {
 	if (allocated)
@@ -671,9 +697,9 @@ FcDirCacheUnload (FcCache *cache)
 }
 
 static FcBool
-FcDirCacheMapHelper (int fd, struct stat *fd_stat, struct stat *dir_stat, void *closure)
+FcDirCacheMapHelper (FcConfig *config, int fd, struct stat *fd_stat, struct stat *dir_stat, void *closure)
 {
-    FcCache *cache = FcDirCacheMapFd (fd, fd_stat, dir_stat);
+    FcCache *cache = FcDirCacheMapFd (config, fd, fd_stat, dir_stat);
 
     if (!cache)
 	return FcFalse;
@@ -690,6 +716,7 @@ FcDirCacheLoad (const FcChar8 *dir, FcConfig *config, FcChar8 **cache_file)
 			    FcDirCacheMapHelper,
 			    &cache, cache_file))
 	return NULL;
+
     return cache;
 }
 
@@ -705,7 +732,7 @@ FcDirCacheLoadFile (const FcChar8 *cache_file, struct stat *file_stat)
     fd = FcDirCacheOpenFile (cache_file, file_stat);
     if (fd < 0)
 	return NULL;
-    cache = FcDirCacheMapFd (fd, file_stat, NULL);
+    cache = FcDirCacheMapFd (FcConfigGetCurrent (), fd, file_stat, NULL);
     close (fd);
     return cache;
 }
@@ -715,7 +742,7 @@ FcDirCacheLoadFile (const FcChar8 *cache_file, struct stat *file_stat)
  * the magic number and the size field
  */
 static FcBool
-FcDirCacheValidateHelper (int fd, struct stat *fd_stat, struct stat *dir_stat, void *closure FC_UNUSED)
+FcDirCacheValidateHelper (FcConfig *config, int fd, struct stat *fd_stat, struct stat *dir_stat, void *closure FC_UNUSED)
 {
     FcBool  ret = FcTrue;
     FcCache	c;
@@ -1080,15 +1107,22 @@ FcDirCacheClean (const FcChar8 *cache_dir, FcBool verbose)
 	}
 	else
 	{
+	    FcChar8 *s;
+
 	    target_dir = FcCacheDir (cache);
-	    if (stat ((char *) target_dir, &target_stat) < 0)
+	    if (sysroot)
+		s = FcStrBuildFilename (sysroot, target_dir, NULL);
+	    else
+		s = FcStrdup (target_dir);
+	    if (stat ((char *) s, &target_stat) < 0)
 	    {
 		if (verbose || FcDebug () & FC_DBG_CACHE)
 		    printf ("%s: %s: missing directory: %s \n",
-			    dir, ent->d_name, target_dir);
+			    dir, ent->d_name, s);
 		remove = FcTrue;
 	    }
 	    FcDirCacheUnload (cache);
+	    FcStrFree (s);
 	}
 	if (remove)
 	{
diff --git a/src/fccfg.c b/src/fccfg.c
index fe69eec..8b62e52 100644
--- a/src/fccfg.c
+++ b/src/fccfg.c
@@ -375,7 +375,7 @@ FcConfigAddDirList (FcConfig *config, FcSetName set, FcStrSet *dirSet)
     while ((dir = FcStrListNext (dirlist)))
     {
 	if (FcDebug () & FC_DBG_FONTSET)
-	    printf ("adding fonts from%s\n", dir);
+	    printf ("adding fonts from %s\n", dir);
 	cache = FcDirCacheRead (dir, FcFalse, config);
 	if (!cache)
 	    continue;
diff --git a/src/fcdir.c b/src/fcdir.c
index 49259c1..b35997f 100644
--- a/src/fcdir.c
+++ b/src/fcdir.c
@@ -69,6 +69,7 @@ FcFileScanFontConfig (FcFontSet		*set,
     FcBool	ret = FcTrue;
     int		id;
     int		count = 0;
+    const FcChar8 *sysroot = FcConfigGetSysRoot (config);
 
     id = 0;
     do
@@ -85,6 +86,28 @@ FcFileScanFontConfig (FcFontSet		*set,
 	font = FcFreeTypeQuery (file, id, blanks, &count);
 	if (FcDebug () & FC_DBG_SCAN)
 	    printf ("done\n");
+	/*
+	 * Get rid of sysroot here so that targeting scan rule may contains FC_FILE pattern
+	 * and they should usually expect without sysroot.
+	 */
+	if (sysroot)
+	{
+	    size_t len = strlen ((const char *)sysroot);
+	    FcChar8 *f = NULL;
+
+	    if (FcPatternObjectGetString (font, FC_FILE_OBJECT, 0, &f) == FcResultMatch &&
+		strncmp ((const char *)f, (const char *)sysroot, len) == 0)
+	    {
+		FcChar8 *s = FcStrdup (f);
+		FcPatternObjectDel (font, FC_FILE_OBJECT);
+		if (s[len] != '/')
+		    len--;
+		else if (s[len+1] == '/')
+		    len++;
+		FcPatternObjectAddString (font, FC_FILE_OBJECT, &s[len]);
+		FcStrFree (s);
+	    }
+	}
 
 	/*
 	 * Edit pattern with user-defined rules
@@ -128,7 +151,23 @@ FcFileScanConfig (FcFontSet	*set,
 		  FcConfig	*config)
 {
     if (FcFileIsDir (file))
-	return FcStrSetAdd (dirs, file);
+    {
+	const FcChar8 *sysroot = FcConfigGetSysRoot (config);
+	const FcChar8 *d;
+	size_t len = strlen ((const char *)sysroot);
+
+	if (sysroot && strncmp ((const char *)file, (const char *)sysroot, len) == 0)
+	{
+	    if (file[len] != '/')
+		len--;
+	    else if (file[len+1] == '/')
+		len++;
+	    d = &file[len];
+	}
+	else
+	    d = file;
+	return FcStrSetAdd (dirs, d);
+    }
     else
     {
 	if (set)
@@ -238,7 +277,7 @@ FcDirScanConfig (FcFontSet	*set,
 	if (scanOnly)
 	{
 	    if (FcFileIsDir (files->strs[i]))
-		FcStrSetAdd (dirs, files->strs[i]);
+		FcFileScanConfig (NULL, dirs, NULL, files->strs[i], config);
 	}
 	else
 	{
@@ -273,9 +312,10 @@ FcDirScan (FcFontSet	    *set,
 
 FcBool
 FcDirScanOnly (FcStrSet		*dirs,
-	       const FcChar8	*dir)
+	       const FcChar8	*dir,
+	       FcConfig		*config)
 {
-    return FcDirScanConfig (NULL, dirs, NULL, dir, FcTrue, NULL, FcTrue);
+    return FcDirScanConfig (NULL, dirs, NULL, dir, FcTrue, config, FcTrue);
 }
 
 /*
@@ -288,11 +328,18 @@ FcDirCacheScan (const FcChar8 *dir, FcConfig *config)
     FcFontSet		*set;
     FcCache		*cache = NULL;
     struct stat		dir_stat;
+    const FcChar8	*sysroot = FcConfigGetSysRoot (config);
+    FcChar8		*d;
+
+    if (sysroot)
+	d = FcStrBuildFilename (sysroot, dir, NULL);
+    else
+	d = FcStrdup (dir);
 
     if (FcDebug () & FC_DBG_FONTSET)
-	printf ("cache scan dir %s\n", dir);
+	printf ("cache scan dir %s\n", d);
 
-    if (FcStatChecksum (dir, &dir_stat) < 0)
+    if (FcStatChecksum (d, &dir_stat) < 0)
 	goto bail;
 
     set = FcFontSetCreate();
@@ -306,7 +353,7 @@ FcDirCacheScan (const FcChar8 *dir, FcConfig *config)
     /*
      * Scan the dir
      */
-    if (!FcDirScanConfig (set, dirs, NULL, dir, FcTrue, config, FcFalse))
+    if (!FcDirScanConfig (set, dirs, NULL, d, FcTrue, config, FcFalse))
 	goto bail2;
 
     /*
@@ -326,20 +373,30 @@ FcDirCacheScan (const FcChar8 *dir, FcConfig *config)
  bail1:
     FcFontSetDestroy (set);
  bail:
+    FcStrFree (d);
+
     return cache;
 }
 
 FcCache *
 FcDirCacheRescan (const FcChar8 *dir, FcConfig *config)
 {
-    FcCache *cache = FcDirCacheLoad (dir, config, NULL);
+    FcCache *cache;
     FcCache *new = NULL;
     struct stat dir_stat;
     FcStrSet *dirs;
+    const FcChar8 *sysroot = FcConfigGetSysRoot (config);
+    FcChar8 *d = NULL;
 
+    cache = FcDirCacheLoad (dir, config, NULL);
     if (!cache)
-	return NULL;
-    if (FcStatChecksum (dir, &dir_stat) < 0)
+	goto bail;
+
+    if (sysroot)
+	d = FcStrBuildFilename (sysroot, dir, NULL);
+    else
+	d = FcStrdup (dir);
+    if (FcStatChecksum (d, &dir_stat) < 0)
 	goto bail;
     dirs = FcStrSetCreate ();
     if (!dirs)
@@ -348,7 +405,7 @@ FcDirCacheRescan (const FcChar8 *dir, FcConfig *config)
     /*
      * Scan the dir
      */
-    if (!FcDirScanConfig (NULL, dirs, NULL, dir, FcTrue, config, FcFalse))
+    if (!FcDirScanConfig (NULL, dirs, NULL, d, FcTrue, config, FcFalse))
 	goto bail1;
     /*
      * Rebuild the cache object
@@ -365,6 +422,9 @@ FcDirCacheRescan (const FcChar8 *dir, FcConfig *config)
 bail1:
     FcStrSetDestroy (dirs);
 bail:
+    if (d)
+	FcStrFree (d);
+
     return new;
 }
 
diff --git a/src/fcinit.c b/src/fcinit.c
index b8d5d06..1e23c1f 100644
--- a/src/fcinit.c
+++ b/src/fcinit.c
@@ -36,13 +36,14 @@
 #endif
 
 static FcConfig *
-FcInitFallbackConfig (void)
+FcInitFallbackConfig (const FcChar8 *sysroot)
 {
     FcConfig	*config;
 
     config = FcConfigCreate ();
     if (!config)
 	goto bail0;
+    FcConfigSetSysRoot (config, sysroot);
     if (!FcConfigAddDir (config, (FcChar8 *) FC_DEFAULT_FONTS))
 	goto bail1;
     if (!FcConfigAddCacheDir (config, (FcChar8 *) FC_CACHEDIR))
@@ -78,8 +79,12 @@ FcInitLoadOwnConfig (FcConfig *config)
 
     if (!FcConfigParseAndLoad (config, 0, FcTrue))
     {
+	const FcChar8 *sysroot = FcConfigGetSysRoot (config);
+	FcConfig *fallback = FcInitFallbackConfig (sysroot);
+
 	FcConfigDestroy (config);
-	return FcInitFallbackConfig ();
+
+	return fallback;
     }
 
     if (config->cacheDirs && config->cacheDirs->num == 0)
@@ -108,13 +113,19 @@ FcInitLoadOwnConfig (FcConfig *config)
 	if (!FcConfigAddCacheDir (config, (FcChar8 *) FC_CACHEDIR) ||
 	    !FcConfigAddCacheDir (config, (FcChar8 *) prefix))
 	{
+	    FcConfig *fallback;
+	    const FcChar8 *sysroot;
+
 	  bail:
+	    sysroot = FcConfigGetSysRoot (config);
 	    fprintf (stderr,
 		     "Fontconfig error: out of memory");
 	    if (prefix)
 		FcStrFree (prefix);
+	    fallback = FcInitFallbackConfig (sysroot);
 	    FcConfigDestroy (config);
-	    return FcInitFallbackConfig ();
+
+	    return fallback;
 	}
 	FcStrFree (prefix);
     }
diff --git a/src/fcint.h b/src/fcint.h
index 6871fdc..d3079ed 100644
--- a/src/fcint.h
+++ b/src/fcint.h
@@ -854,7 +854,8 @@ FcDirScanConfig (FcFontSet	*set,
 
 FcPrivate FcBool
 FcDirScanOnly (FcStrSet		*dirs,
-	       const FcChar8	*dir);
+	       const FcChar8	*dir,
+	       FcConfig		*config);
 
 /* fcfont.c */
 FcPrivate int
diff --git a/src/fcxml.c b/src/fcxml.c
index c68b0cf..3dc1357 100644
--- a/src/fcxml.c
+++ b/src/fcxml.c
@@ -3129,11 +3129,12 @@ FcConfigParseAndLoad (FcConfig	    *config,
 {
 
     XML_Parser	    p;
-    FcChar8	    *filename;
+    FcChar8	    *filename, *f;
     int		    fd;
     int		    len;
     FcConfigParse   parse;
     FcBool	    error = FcTrue;
+    const FcChar8   *sysroot = FcConfigGetSysRoot (config);
 
 #ifdef ENABLE_LIBXML2
     xmlSAXHandler   sax;
@@ -3158,9 +3159,14 @@ FcConfigParseAndLoad (FcConfig	    *config,
     }
 #endif
 
-    filename = FcConfigFilename (name);
-    if (!filename)
+    f = FcConfigFilename (name);
+    if (!f)
 	goto bail0;
+    if (sysroot)
+	filename = FcStrBuildFilename (sysroot, f, NULL);
+    else
+	filename = FcStrdup (f);
+    FcStrFree (f);
 
     if (FcStrSetMember (config->configFiles, filename))
     {


More information about the Fontconfig mailing list