summaryrefslogtreecommitdiff
path: root/src/fccache.c
diff options
context:
space:
mode:
authorAkira TAGOH <akira@tagoh.org>2019-10-28 17:11:38 +0900
committerAkira TAGOH <akira@tagoh.org>2019-10-28 17:15:07 +0900
commitc9862b6ea7c3234b29f6500c7d07359847e55ed7 (patch)
tree308de53853fc87c87e2477eac1cda8942f5e3ab2 /src/fccache.c
parentcd51cb241aad7b362b793200ca7d42595c14f52b (diff)
Read latest cache in paths
Right now fontconfig uses a cache found first in a path and cachedirs are the order of the system-wide path and then the user path. this is due to avoid writing caches into the user path when running as root. However, changing caches by certain config only, e.g. using <match target="scan"> may not take effect by this behavior, because it may be stored into the user path. Thus, needing to find the latest cache out from paths. Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/issues/182
Diffstat (limited to 'src/fccache.c')
-rw-r--r--src/fccache.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/fccache.c b/src/fccache.c
index 0976201..4acde22 100644
--- a/src/fccache.c
+++ b/src/fccache.c
@@ -338,7 +338,7 @@ FcDirCacheOpenFile (const FcChar8 *cache_file, struct stat *file_stat)
static FcBool
FcDirCacheProcess (FcConfig *config, const FcChar8 *dir,
FcBool (*callback) (FcConfig *config, int fd, struct stat *fd_stat,
- struct stat *dir_stat, void *closure),
+ struct stat *dir_stat, struct timeval *cache_mtime, void *closure),
void *closure, FcChar8 **cache_file_ret)
{
int fd = -1;
@@ -348,6 +348,7 @@ FcDirCacheProcess (FcConfig *config, const FcChar8 *dir,
struct stat file_stat, dir_stat;
FcBool ret = FcFalse;
const FcChar8 *sysroot = FcConfigGetSysRoot (config);
+ struct timeval latest_mtime = (struct timeval){ 0 };
if (sysroot)
d = FcStrBuildFilename (sysroot, dir, NULL);
@@ -383,15 +384,18 @@ FcDirCacheProcess (FcConfig *config, const FcChar8 *dir,
#endif
fd = FcDirCacheOpenFile (cache_hashed, &file_stat);
if (fd >= 0) {
- ret = (*callback) (config, fd, &file_stat, &dir_stat, closure);
+ ret = (*callback) (config, fd, &file_stat, &dir_stat, &latest_mtime, closure);
close (fd);
if (ret)
{
if (cache_file_ret)
+ {
+ if (*cache_file_ret)
+ FcStrFree (*cache_file_ret);
*cache_file_ret = cache_hashed;
+ }
else
FcStrFree (cache_hashed);
- break;
}
}
#ifndef _WIN32
@@ -414,7 +418,8 @@ FcDirCacheProcess (FcConfig *config, const FcChar8 *dir,
}
}
#endif
- FcStrFree (cache_hashed);
+ else
+ FcStrFree (cache_hashed);
}
FcStrListDone (list);
@@ -998,12 +1003,31 @@ FcDirCacheUnload (FcCache *cache)
}
static FcBool
-FcDirCacheMapHelper (FcConfig *config, 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, struct timeval *latest_cache_mtime, void *closure)
{
FcCache *cache = FcDirCacheMapFd (config, fd, fd_stat, dir_stat);
+ struct timeval cache_mtime;
if (!cache)
return FcFalse;
+ cache_mtime.tv_sec = fd_stat->st_mtime;
+#ifdef HAVE_STRUCT_STAT_ST_MTIM
+ cache_mtime.tv_usec = fd_stat->st_mtim.tv_nsec / 1000;
+#else
+ cache_mtime.tv_usec = 0;
+#endif
+ if (timercmp (latest_cache_mtime, &cache_mtime, <))
+ {
+ if (*((FcCache **) closure))
+ FcDirCacheUnload (*((FcCache **) closure));
+ }
+ else
+ {
+ FcDirCacheUnload (cache);
+ return FcFalse;
+ }
+ latest_cache_mtime->tv_sec = cache_mtime.tv_sec;
+ latest_cache_mtime->tv_usec = cache_mtime.tv_usec;
*((FcCache **) closure) = cache;
return FcTrue;
}
@@ -1093,7 +1117,7 @@ FcDirChecksumNano (struct stat *statb)
* the magic number and the size field
*/
static FcBool
-FcDirCacheValidateHelper (FcConfig *config, 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, struct timeval *latest_cache_mtime, void *closure FC_UNUSED)
{
FcBool ret = FcTrue;
FcCache c;