aboutsummaryrefslogtreecommitdiff
path: root/fontconfig/src/fccache.c
diff options
context:
space:
mode:
Diffstat (limited to 'fontconfig/src/fccache.c')
-rw-r--r--fontconfig/src/fccache.c99
1 files changed, 68 insertions, 31 deletions
diff --git a/fontconfig/src/fccache.c b/fontconfig/src/fccache.c
index 2c631256b..9f1c29827 100644
--- a/fontconfig/src/fccache.c
+++ b/fontconfig/src/fccache.c
@@ -124,6 +124,7 @@ FcDirCacheUnlink (const FcChar8 *dir, FcConfig *config)
FcChar8 cache_base[CACHEBASE_LEN];
FcStrList *list;
FcChar8 *cache_dir;
+ const FcChar8 *sysroot = FcConfigGetSysRoot (config);
FcDirCacheBasename (dir, cache_base);
@@ -133,7 +134,10 @@ FcDirCacheUnlink (const FcChar8 *dir, FcConfig *config)
while ((cache_dir = FcStrListNext (list)))
{
- cache_hashed = FcStrPlus (cache_dir, cache_base);
+ if (sysroot)
+ cache_hashed = FcStrBuildFilename (sysroot, cache_dir, cache_base, NULL);
+ else
+ cache_hashed = FcStrBuildFilename (cache_dir, cache_base, NULL);
if (!cache_hashed)
break;
(void) unlink ((char *) cache_hashed);
@@ -197,7 +201,13 @@ FcDirCacheProcess (FcConfig *config, const FcChar8 *dir,
while ((cache_dir = FcStrListNext (list)))
{
- FcChar8 *cache_hashed = FcStrPlus (cache_dir, cache_base);
+ const FcChar8 *sysroot = FcConfigGetSysRoot (config);
+ FcChar8 *cache_hashed;
+
+ if (sysroot)
+ cache_hashed = FcStrBuildFilename (sysroot, cache_dir, cache_base, NULL);
+ else
+ cache_hashed = FcStrBuildFilename (cache_dir, cache_base, NULL);
if (!cache_hashed)
break;
fd = FcDirCacheOpenFile (cache_hashed, &file_stat);
@@ -859,11 +869,12 @@ FcDirCacheWrite (FcCache *cache, FcConfig *config)
FcAtomic *atomic;
FcStrList *list;
FcChar8 *cache_dir = NULL;
- FcChar8 *test_dir;
+ FcChar8 *test_dir, *d = NULL;
FcCacheSkip *skip;
struct stat cache_stat;
unsigned int magic;
int written;
+ const FcChar8 *sysroot = FcConfigGetSysRoot (config);
/*
* Write it to the first directory in the list which is writable
@@ -872,10 +883,18 @@ FcDirCacheWrite (FcCache *cache, FcConfig *config)
list = FcStrListCreate (config->cacheDirs);
if (!list)
return FcFalse;
- while ((test_dir = FcStrListNext (list))) {
- if (access ((char *) test_dir, W_OK) == 0)
+ while ((test_dir = FcStrListNext (list)))
+ {
+ if (d)
+ FcStrFree (d);
+ if (sysroot)
+ d = FcStrBuildFilename (sysroot, test_dir, NULL);
+ else
+ d = FcStrCopyFilename (test_dir);
+
+ if (access ((char *) d, W_OK) == 0)
{
- cache_dir = test_dir;
+ cache_dir = FcStrCopyFilename (d);
break;
}
else
@@ -883,35 +902,38 @@ FcDirCacheWrite (FcCache *cache, FcConfig *config)
/*
* If the directory doesn't exist, try to create it
*/
- if (access ((char *) test_dir, F_OK) == -1) {
- if (FcMakeDirectory (test_dir))
+ if (access ((char *) d, F_OK) == -1) {
+ if (FcMakeDirectory (d))
{
- cache_dir = test_dir;
+ cache_dir = FcStrCopyFilename (d);
/* Create CACHEDIR.TAG */
- FcDirCacheCreateTagFile (cache_dir);
+ FcDirCacheCreateTagFile (d);
break;
}
}
/*
* Otherwise, try making it writable
*/
- else if (chmod ((char *) test_dir, 0755) == 0)
+ else if (chmod ((char *) d, 0755) == 0)
{
- cache_dir = test_dir;
+ cache_dir = FcStrCopyFilename (d);
/* Try to create CACHEDIR.TAG too */
- FcDirCacheCreateTagFile (cache_dir);
+ FcDirCacheCreateTagFile (d);
break;
}
}
}
+ if (d)
+ FcStrFree (d);
FcStrListDone (list);
if (!cache_dir)
return FcFalse;
FcDirCacheBasename (dir, cache_base);
- cache_hashed = FcStrPlus (cache_dir, cache_base);
+ cache_hashed = FcStrBuildFilename (cache_dir, cache_base, NULL);
if (!cache_hashed)
return FcFalse;
+ FcStrFree (cache_dir);
if (FcDebug () & FC_DBG_CACHE)
printf ("FcDirCacheWriteDir dir \"%s\" file \"%s\"\n",
@@ -989,31 +1011,37 @@ FcDirCacheClean (const FcChar8 *cache_dir, FcBool verbose)
{
DIR *d;
struct dirent *ent;
- FcChar8 *dir_base;
+ FcChar8 *dir;
FcBool ret = FcTrue;
FcBool remove;
FcCache *cache;
struct stat target_stat;
+ const FcChar8 *sysroot;
- dir_base = FcStrPlus (cache_dir, (FcChar8 *) FC_DIR_SEPARATOR_S);
- if (!dir_base)
+ /* FIXME: this API needs to support non-current FcConfig */
+ sysroot = FcConfigGetSysRoot (NULL);
+ if (sysroot)
+ dir = FcStrBuildFilename (sysroot, cache_dir, NULL);
+ else
+ dir = FcStrCopyFilename (cache_dir);
+ if (!dir)
{
fprintf (stderr, "Fontconfig error: %s: out of memory\n", cache_dir);
return FcFalse;
}
- if (access ((char *) cache_dir, W_OK) != 0)
+ if (access ((char *) dir, W_OK) != 0)
{
if (verbose || FcDebug () & FC_DBG_CACHE)
- printf ("%s: not cleaning %s cache directory\n", cache_dir,
- access ((char *) cache_dir, F_OK) == 0 ? "unwritable" : "non-existent");
+ printf ("%s: not cleaning %s cache directory\n", dir,
+ access ((char *) dir, F_OK) == 0 ? "unwritable" : "non-existent");
goto bail0;
}
if (verbose || FcDebug () & FC_DBG_CACHE)
- printf ("%s: cleaning cache directory\n", cache_dir);
- d = opendir ((char *) cache_dir);
+ printf ("%s: cleaning cache directory\n", dir);
+ d = opendir ((char *) dir);
if (!d)
{
- perror ((char *) cache_dir);
+ perror ((char *) dir);
ret = FcFalse;
goto bail0;
}
@@ -1030,10 +1058,10 @@ FcDirCacheClean (const FcChar8 *cache_dir, FcBool verbose)
strcmp(ent->d_name + 32, "-" FC_ARCHITECTURE FC_CACHE_SUFFIX))
continue;
- file_name = FcStrPlus (dir_base, (FcChar8 *) ent->d_name);
+ file_name = FcStrBuildFilename (dir, (FcChar8 *)ent->d_name, NULL);
if (!file_name)
{
- fprintf (stderr, "Fontconfig error: %s: allocation failure\n", cache_dir);
+ fprintf (stderr, "Fontconfig error: %s: allocation failure\n", dir);
ret = FcFalse;
break;
}
@@ -1042,7 +1070,7 @@ FcDirCacheClean (const FcChar8 *cache_dir, FcBool verbose)
if (!cache)
{
if (verbose || FcDebug () & FC_DBG_CACHE)
- printf ("%s: invalid cache file: %s\n", cache_dir, ent->d_name);
+ printf ("%s: invalid cache file: %s\n", dir, ent->d_name);
remove = FcTrue;
}
else
@@ -1052,7 +1080,7 @@ FcDirCacheClean (const FcChar8 *cache_dir, FcBool verbose)
{
if (verbose || FcDebug () & FC_DBG_CACHE)
printf ("%s: %s: missing directory: %s \n",
- cache_dir, ent->d_name, target_dir);
+ dir, ent->d_name, target_dir);
remove = FcTrue;
}
FcDirCacheUnload (cache);
@@ -1070,7 +1098,7 @@ FcDirCacheClean (const FcChar8 *cache_dir, FcBool verbose)
closedir (d);
bail0:
- FcStrFree (dir_base);
+ FcStrFree (dir);
return ret;
}
@@ -1394,7 +1422,7 @@ FcDirCacheCreateTagFile (const FcChar8 *cache_dir)
if (access ((char *) cache_dir, W_OK) == 0)
{
/* Create CACHEDIR.TAG */
- cache_tag = FcStrPlus (cache_dir, (const FcChar8 *) FC_DIR_SEPARATOR_S "CACHEDIR.TAG");
+ cache_tag = FcStrBuildFilename (cache_dir, "CACHEDIR.TAG", NULL);
if (!cache_tag)
return FcFalse;
atomic = FcAtomicCreate ((FcChar8 *)cache_tag);
@@ -1438,8 +1466,9 @@ FcDirCacheCreateTagFile (const FcChar8 *cache_dir)
void
FcCacheCreateTagFile (const FcConfig *config)
{
- FcChar8 *cache_dir = NULL;
+ FcChar8 *cache_dir = NULL, *d = NULL;
FcStrList *list;
+ const FcChar8 *sysroot = FcConfigGetSysRoot (config);
list = FcConfigGetCacheDirs (config);
if (!list)
@@ -1447,9 +1476,17 @@ FcCacheCreateTagFile (const FcConfig *config)
while ((cache_dir = FcStrListNext (list)))
{
- if (FcDirCacheCreateTagFile (cache_dir))
+ if (d)
+ FcStrFree (d);
+ if (sysroot)
+ d = FcStrBuildFilename (sysroot, cache_dir, NULL);
+ else
+ d = FcStrCopyFilename (cache_dir);
+ if (FcDirCacheCreateTagFile (d))
break;
}
+ if (d)
+ FcStrFree (d);
FcStrListDone (list);
}