+2005-10-04 Patrick Lam <plam@mit.edu>
+ * src/fccache.c (FcDirCacheValid, FcDirCacheUnlink,
+ FcDirCacheHasCurrentArch):
+ * fc-cache/fc-cache.c (scanDirs):
+ * fontconfig/fontconfig.h:
+
+ Add new API which unlinks directory caches and checks dir caches
+ for existence of appropriate sections. Fix fc-cache to unlink
+ stale cache files and save directory caches that lack relevant
+ sections.
+
2005-10-03 Patrick Lam <plam@mit.edu>
* src/fccache.c (FcDirCacheValid):
ret++;
continue;
}
- if (!force && FcDirCacheValid (dir))
+ if (!force && FcDirCacheValid (dir) && FcDirCacheHasCurrentArch (dir))
{
if (verbose)
printf ("skipping, %d fonts, %d dirs\n",
printf ("caching, %d fonts, %d dirs\n",
set->nfont, nsubdirs (subdirs));
+ if (!FcDirCacheValid (dir))
+ if (!FcDirCacheUnlink (dir))
+ ret++;
+
if (!FcDirSave (set, subdirs, dir))
{
fprintf (stderr, "Can't save cache in \"%s\"\n", dir);
return FcFalse;
}
+/* Does not check that the cache has the appropriate arch section. */
FcBool
FcDirCacheValid (const FcChar8 *dir)
{
FcChar8 *cache_file = FcStrPlus (dir, (FcChar8 *) "/" FC_DIR_CACHE_FILE);
struct stat file_stat, dir_stat;
- int fd;
- off_t current_arch_start;
- char *current_arch_machine_name;
if (stat ((char *) dir, &dir_stat) < 0)
{
return FcFalse;
}
+ FcStrFree (cache_file);
+ /*
+ * If the directory has been modified more recently than
+ * the cache file, the cache is not valid
+ */
+ if (dir_stat.st_mtime - file_stat.st_mtime > 0)
+ return FcFalse;
+ return FcTrue;
+}
+
+/* Assumes that the cache file in 'dir' exists.
+ * Checks that the cache has the appropriate arch section. */
+FcBool
+FcDirCacheHasCurrentArch (const FcChar8 *dir)
+{
+ FcChar8 *cache_file = FcStrPlus (dir, (FcChar8 *) "/" FC_DIR_CACHE_FILE);
+ int fd;
+ off_t current_arch_start;
+ char *current_arch_machine_name;
+
current_arch_machine_name = FcCacheMachineSignature();
- fd = open(cache_file, O_RDONLY);
+ fd = open ((char *)cache_file, O_RDONLY);
if (fd == -1)
return FcFalse;
if (current_arch_start < 0)
return FcFalse;
+
+ return FcTrue;
+}
- FcStrFree (cache_file);
- /*
- * If the directory has been modified more recently than
- * the cache file, the cache is not valid
- */
- if (dir_stat.st_mtime - file_stat.st_mtime > 0)
+FcBool
+FcDirCacheUnlink (const FcChar8 *dir)
+{
+ FcChar8 *cache_file = FcStrPlus (dir, (FcChar8 *) "/" FC_DIR_CACHE_FILE);
+
+ if (!unlink ((char *)cache_file))
return FcFalse;
+
+ FcStrFree (cache_file);
+
return FcTrue;
}