Have fc-cache remove invalid cache files from cache directories.

Old cache file versions, or corrupted cache files should be removed when
cleaning cache directories with fc-cache. This only affects filenames which
match the fontconfig cache file format, so other files will be left alone.
This commit is contained in:
Keith Packard 2007-10-18 05:05:59 -07:00
parent 238489030a
commit 2a3e3c442d
1 changed files with 18 additions and 16 deletions

View File

@ -301,16 +301,17 @@ cleanCacheDirectory (FcConfig *config, FcChar8 *dir, FcBool verbose)
ret = FcFalse; ret = FcFalse;
break; break;
} }
remove = FcFalse;
cache = FcDirCacheLoadFile (file_name, &file_stat); cache = FcDirCacheLoadFile (file_name, &file_stat);
if (!cache) if (!cache)
{ {
fprintf (stderr, "%s: invalid cache file: %s\n", dir, ent->d_name); if (verbose)
FcStrFree (file_name); printf ("%s: invalid cache file: %s\n", dir, ent->d_name);
ret = FcFalse; remove = FcTrue;
continue;
} }
else
{
target_dir = FcCacheDir (cache); target_dir = FcCacheDir (cache);
remove = FcFalse;
if (stat ((char *) target_dir, &target_stat) < 0) if (stat ((char *) target_dir, &target_stat) < 0)
{ {
if (verbose) if (verbose)
@ -325,6 +326,7 @@ cleanCacheDirectory (FcConfig *config, FcChar8 *dir, FcBool verbose)
dir, ent->d_name, target_dir); dir, ent->d_name, target_dir);
remove = FcTrue; remove = FcTrue;
} }
}
if (remove) if (remove)
{ {
if (unlink ((char *) file_name) < 0) if (unlink ((char *) file_name) < 0)