+FcCache *
+FcDirCacheRescan (const FcChar8 *dir, FcConfig *config)
+{
+ FcCache *cache;
+ FcCache *new = NULL;
+ struct stat dir_stat;
+ FcStrSet *dirs;
+ const FcChar8 *sysroot = FcConfigGetSysRoot (config);
+ FcChar8 *d = NULL;
+ int fd = -1;
+
+ cache = FcDirCacheLoad (dir, config, NULL);
+ if (!cache)
+ goto bail;
+
+ if (sysroot)
+ d = FcStrBuildFilename (sysroot, dir, NULL);
+ else
+ d = FcStrdup (dir);
+ if (FcStatChecksum (d, &dir_stat) < 0)
+ goto bail;
+ dirs = FcStrSetCreateEx (FCSS_GROW_BY_64);
+ if (!dirs)
+ goto bail;
+
+ fd = FcDirCacheLock (dir, config);
+ /*
+ * Scan the dir
+ */
+ if (!FcDirScanConfig (NULL, dirs, NULL, d, FcTrue, config))
+ goto bail1;
+ /*
+ * Rebuild the cache object
+ */
+ new = FcDirCacheRebuild (cache, &dir_stat, dirs);
+ if (!new)
+ goto bail1;
+ FcDirCacheUnload (cache);
+ /*
+ * Write out the cache file, ignoring any troubles
+ */
+ FcDirCacheWrite (new, config);
+
+bail1:
+ FcDirCacheUnlock (fd);
+ FcStrSetDestroy (dirs);
+bail:
+ if (d)
+ FcStrFree (d);
+
+ return new;
+}
+