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.
This commit is contained in:
parent
6bf2380478
commit
55c8fa4f08
11
ChangeLog
11
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):
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
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);
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue