Commit d17f5561 authored by Akira TAGOH's avatar Akira TAGOH

Read the config files and fonts on the sysroot when --sysroot is given to fc-cache

Fix for e96d7760

https://bugs.freedesktop.org/show_bug.cgi?id=59456
parent 8f62ccaa
......@@ -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);
}
......
......@@ -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)
{
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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);
}
......
......@@ -854,7 +854,8 @@ FcDirScanConfig (FcFontSet *set,
FcPrivate FcBool
FcDirScanOnly (FcStrSet *dirs,
const FcChar8 *dir);
const FcChar8 *dir,
FcConfig *config);
/* fcfont.c */
FcPrivate int
......
......@@ -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))
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment