]> git.wh0rd.org - fontconfig.git/commitdiff
Add new API which unlinks directory caches and checks dir caches for
authorPatrick Lam <plam@MIT.EDU>
Wed, 5 Oct 2005 00:34:52 +0000 (00:34 +0000)
committerPatrick Lam <plam@MIT.EDU>
Wed, 5 Oct 2005 00:34:52 +0000 (00:34 +0000)
    existence of appropriate sections. Fix fc-cache to unlink stale cache
    files and save directory caches that lack relevant sections.

ChangeLog
fc-cache/fc-cache.c
fontconfig/fontconfig.h
src/fccache.c

index d85f2b28e1fbbc9ae32826cfd149e9ce188d10db..b7cfb91d206461ac243bafebdd56154d9359279f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+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):
 
index 20c7c95bb5e92c952c5b64a7de760739a723c7af..388baa7651d3386cabf8887eeed3a2168e787952 100644 (file)
@@ -191,7 +191,7 @@ scanDirs (FcStrList *list, FcConfig *config, char *program, FcBool force, FcBool
            ret++;
            continue;
        }
-       if (!force && FcDirCacheValid (dir))
+       if (!force && FcDirCacheValid (dir) && FcDirCacheHasCurrentArch (dir))
        {
            if (verbose)
                printf ("skipping, %d fonts, %d dirs\n",
@@ -203,6 +203,10 @@ scanDirs (FcStrList *list, FcConfig *config, char *program, FcBool force, FcBool
                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);
index 34e7b8bdde964674053ac14904db8f50d2e88005..2ffcb245e2f5963030db448c5a8171fb1c658c15 100644 (file)
@@ -273,6 +273,12 @@ _FCFUNCPROTOBEGIN
 FcBool
 FcDirCacheValid (const FcChar8 *cache_file);
 
+FcBool
+FcDirCacheHasCurrentArch (const FcChar8 *dir);
+
+FcBool
+FcDirCacheUnlink (const FcChar8 *dir);
+
 /* fcblanks.c */
 FcBlanks *
 FcBlanksCreate (void);
index 7ff9fc617e95da09cf0888df2840cf22f2115543..43e45af92cfbbcdb59595d49818c57274348bc7c 100644 (file)
@@ -517,14 +517,12 @@ FcCacheCopyOld (int fd, int fd_orig, off_t start)
     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)
     {
@@ -537,8 +535,28 @@ FcDirCacheValid (const FcChar8 *dir)
         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;
 
@@ -547,14 +565,20 @@ FcDirCacheValid (const FcChar8 *dir)
 
     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;
 }