Bug 106459 - fc-cache doesn't use -y option for .uuid files

https://bugs.freedesktop.org/show_bug.cgi?id=106459
This commit is contained in:
Akira TAGOH 2018-05-13 16:21:58 +09:00
parent cfb21c7d85
commit 0b85e77ede
2 changed files with 62 additions and 11 deletions

View File

@ -51,13 +51,23 @@ FcDirCacheCreateUUID (FcChar8 *dir,
FcBool force, FcBool force,
FcConfig *config) FcConfig *config)
{ {
const FcChar8 *sysroot = FcConfigGetSysRoot (config);
FcChar8 *target;
FcBool ret = FcTrue; FcBool ret = FcTrue;
#ifndef _WIN32 #ifndef _WIN32
FcChar8 *uuidname; FcChar8 *uuidname;
uuidname = FcStrBuildFilename (dir, ".uuid", NULL); if (sysroot)
target = FcStrBuildFilename (sysroot, dir, NULL);
else
target = FcStrdup (dir);
uuidname = FcStrBuildFilename (target, ".uuid", NULL);
if (!uuidname) if (!uuidname)
{
FcStrFree (target);
return FcFalse; return FcFalse;
}
if (force || access ((const char *) uuidname, F_OK) < 0) if (force || access ((const char *) uuidname, F_OK) < 0)
{ {
@ -69,7 +79,7 @@ FcDirCacheCreateUUID (FcChar8 *dir,
struct stat statb; struct stat statb;
struct timeval times[2]; struct timeval times[2];
if (FcStat (dir, &statb) != 0) if (FcStat (target, &statb) != 0)
{ {
ret = FcFalse; ret = FcFalse;
goto bail1; goto bail1;
@ -96,7 +106,7 @@ FcDirCacheCreateUUID (FcChar8 *dir,
hash_add = FcHashTableReplace; hash_add = FcHashTableReplace;
else else
hash_add = FcHashTableAdd; hash_add = FcHashTableAdd;
if (!hash_add (config->uuid_table, dir, uuid)) if (!hash_add (config->uuid_table, target, uuid))
{ {
ret = FcFalse; ret = FcFalse;
goto bail3; goto bail3;
@ -124,14 +134,15 @@ FcDirCacheCreateUUID (FcChar8 *dir,
times[0].tv_usec = 0; times[0].tv_usec = 0;
times[1].tv_usec = 0; times[1].tv_usec = 0;
#endif #endif
if (utimes ((const char *) dir, times) != 0) if (utimes ((const char *) target, times) != 0)
{ {
fprintf (stderr, "Unable to revert mtime: %s\n", dir); fprintf (stderr, "Unable to revert mtime: %s\n", target);
} }
} }
} }
bail1: bail1:
FcStrFree (uuidname); FcStrFree (uuidname);
FcStrFree (target);
#endif #endif
return ret; return ret;
@ -144,10 +155,17 @@ FcDirCacheReadUUID (FcChar8 *dir,
{ {
void *u; void *u;
uuid_t uuid; uuid_t uuid;
const FcChar8 *sysroot = FcConfigGetSysRoot (config);
FcChar8 *target;
if (!FcHashTableFind (config->uuid_table, dir, &u)) if (sysroot)
target = FcStrBuildFilename (sysroot, dir, NULL);
else
target = FcStrdup (dir);
if (!FcHashTableFind (config->uuid_table, target, &u))
{ {
FcChar8 *uuidname = FcStrBuildFilename (dir, ".uuid", NULL); FcChar8 *uuidname = FcStrBuildFilename (target, ".uuid", NULL);
int fd; int fd;
if ((fd = FcOpen ((char *) uuidname, O_RDONLY)) >= 0) if ((fd = FcOpen ((char *) uuidname, O_RDONLY)) >= 0)
@ -162,7 +180,7 @@ FcDirCacheReadUUID (FcChar8 *dir,
{ {
if (FcDebug () & FC_DBG_CACHE) if (FcDebug () & FC_DBG_CACHE)
printf ("FcDirCacheReadUUID %s -> %s\n", uuidname, suuid); printf ("FcDirCacheReadUUID %s -> %s\n", uuidname, suuid);
FcHashTableAdd (config->uuid_table, dir, uuid); FcHashTableAdd (config->uuid_table, target, uuid);
} }
} }
close (fd); close (fd);
@ -176,6 +194,7 @@ FcDirCacheReadUUID (FcChar8 *dir,
} }
else else
FcHashUuidFree (u); FcHashUuidFree (u);
FcStrFree (target);
} }
#endif #endif
@ -259,18 +278,25 @@ static FcChar8 *
FcDirCacheBasenameUUID (const FcChar8 *dir, FcChar8 cache_base[CACHEBASE_LEN], FcConfig *config) FcDirCacheBasenameUUID (const FcChar8 *dir, FcChar8 cache_base[CACHEBASE_LEN], FcConfig *config)
{ {
void *u; void *u;
FcChar8 *alias; FcChar8 *alias, *target;
const FcChar8 *sysroot = FcConfigGetSysRoot (config);
if (!FcHashTableFind (config->alias_table, dir, (void **)&alias)) if (!FcHashTableFind (config->alias_table, dir, (void **)&alias))
alias = FcStrdup (dir); alias = FcStrdup (dir);
if (FcHashTableFind (config->uuid_table, alias, &u)) if (sysroot)
target = FcStrBuildFilename (sysroot, alias, NULL);
else
target = FcStrdup (alias);
if (FcHashTableFind (config->uuid_table, target, &u))
{ {
uuid_unparse (u, (char *) cache_base); uuid_unparse (u, (char *) cache_base);
strcat ((char *) cache_base, "-" FC_ARCHITECTURE FC_CACHE_SUFFIX); strcat ((char *) cache_base, "-" FC_ARCHITECTURE FC_CACHE_SUFFIX);
FcHashUuidFree (u); FcHashUuidFree (u);
FcStrFree (target);
FcStrFree (alias); FcStrFree (alias);
return cache_base; return cache_base;
} }
FcStrFree (target);
FcStrFree (alias); FcStrFree (alias);
return NULL; return NULL;
} }

View File

@ -203,4 +203,29 @@ fi
rm -rf $TESTTMPDIR out1 out2 xxx bind-fonts.conf rm -rf $TESTTMPDIR out1 out2 xxx bind-fonts.conf
fi fi
dotest "sysroot option"
prep
mkdir -p $MyPWD/sysroot/$FONTDIR
mkdir -p $MyPWD/sysroot/$CACHEDIR
cp $FONT1 $MyPWD/sysroot/$FONTDIR
cp $MyPWD/fonts.conf $MyPWD/sysroot/$MyPWD/fonts.conf
$FCCACHE -y $MyPWD/sysroot
stat $MyPWD/sysroot/$FONTDIR/.uuid
if test $? != 0; then
echo "*** Test failed: $TEST"
exit 1
fi
dotest "creating uuid-based cache file on sysroot"
uuid=`cat $MyPWD/sysroot/$FONTDIR/.uuid`
ls $MyPWD/sysroot/$CACHEDIR/$uuid*
if [ $? != 0 ]; then
echo "*** Test failed: $TEST"
echo "No cache for $uuid"
ls $MyPWD/sysroot/$CACHEDIR
exit 1
fi
rm -rf $MyPWD/sysroot
rm -rf $FONTDIR $CACHEFILE $CACHEDIR $FONTCONFIG_FILE out rm -rf $FONTDIR $CACHEFILE $CACHEDIR $FONTCONFIG_FILE out