diff options
author | Akira TAGOH <akira@tagoh.org> | 2020-05-12 21:03:28 +0900 |
---|---|---|
committer | Akira TAGOH <akira@tagoh.org> | 2020-05-12 21:06:10 +0900 |
commit | fdbd9d13b7f7afb9eff02894e47b8912f065eee9 (patch) | |
tree | 008c5e77c0738a0d95c5aa067df47c929582152d /src | |
parent | 6edaaa4d1823518a97fb4cc3004d110b1046f742 (diff) | |
download | fontconfig-fdbd9d13b7f7afb9eff02894e47b8912f065eee9.tar.gz |
Fix cache conflicts on OSTree based system
mtime isn't reliable to detect updates of fonts on OSTree based system
since they reset mtime to 0 for system files.
Due to this, there are the situation likely to happen where mtime is
newer but content is older.
Fortunately, OSTree based system requires reboot to deploy changes. so
we can assume we won't see any changes on system fonts. so system caches
are always up-to-date. we can ignore meta data for system fonts in
user caches.
Diffstat (limited to 'src')
-rw-r--r-- | src/fccache.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/fccache.c b/src/fccache.c index 2d398c7..7139b08 100644 --- a/src/fccache.c +++ b/src/fccache.c @@ -845,7 +845,7 @@ FcCacheTimeValid (FcConfig *config, FcCache *cache, struct stat *dir_stat) FcCacheDir (cache), cache->checksum, (int) dir_stat->st_mtime); #endif - return cache->checksum == (int) dir_stat->st_mtime && fnano; + return dir_stat->st_mtime == 0 || (cache->checksum == (int) dir_stat->st_mtime && fnano); } static FcBool @@ -1041,17 +1041,39 @@ static FcBool 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; + struct timeval cache_mtime, zero_mtime = { 0, 0}, dir_mtime; if (!cache) return FcFalse; cache_mtime.tv_sec = fd_stat->st_mtime; + dir_mtime.tv_sec = dir_stat->st_mtime; #ifdef HAVE_STRUCT_STAT_ST_MTIM cache_mtime.tv_usec = fd_stat->st_mtim.tv_nsec / 1000; + dir_mtime.tv_usec = dir_stat->st_mtim.tv_nsec / 1000; #else cache_mtime.tv_usec = 0; + dir_mtime.tv_usec = 0; #endif - if (timercmp (latest_cache_mtime, &cache_mtime, <)) + /* special take care of OSTree */ + if (!timercmp (&zero_mtime, &dir_mtime, !=)) + { + if (!timercmp (&zero_mtime, &cache_mtime, !=)) + { + if (*((FcCache **) closure)) + FcDirCacheUnload (*((FcCache **) closure)); + } + else if (*((FcCache **) closure) && !timercmp (&zero_mtime, latest_cache_mtime, !=)) + { + FcDirCacheUnload (cache); + return FcFalse; + } + else if (timercmp (latest_cache_mtime, &cache_mtime, <)) + { + if (*((FcCache **) closure)) + FcDirCacheUnload (*((FcCache **) closure)); + } + } + else if (timercmp (latest_cache_mtime, &cache_mtime, <)) { if (*((FcCache **) closure)) FcDirCacheUnload (*((FcCache **) closure)); |