Compare device numbers as well as inodes. Always normalize directory names

before comparing them.
Allocate extra space for appended '/' in directory name.
reviewed by: plam
This commit is contained in:
Patrick Lam 2006-01-14 21:23:03 +00:00
parent df3efc11a9
commit 8a0b0ed6d0
8 changed files with 49 additions and 14 deletions

View File

@ -1,3 +1,22 @@
2006-01-14 Patrick Lam <plam@mit.edu>
* fc-cache/fc-cache.c (scanDirs):
* fontconfig/fontconfig.h:
* src/fccache.c (FcGlobalCacheReadDir, FcGlobalCacheUpdate,
FcGlobalCacheSave, FcDirCacheUnlink, FcDirCacheOpen):
* src/fccfg.c (FcConfigBuildFonts, FcConfigNormalizeFontDir):
* src/fcdir.c (FcDirScanConfig):
* src/fcint.h:
Compare device numbers as well as inodes.
Always normalize directory names before comparing them.
2006-01-11 Mike Fabian <mfabian@suse.de>
reviewed by: plam
* fc-cat/fc-cat.c (FcCacheGlobalFileReadAndPrint):
Allocate extra space for appended '/' in directory name.
2006-01-10 Patrick Lam <plam@mit.edu>
* src/fccache.c (FcDirCacheConsume, FcDirCacheOpen,
FcDirCacheValid, FcDirCacheHasCurrentArch,

View File

@ -204,7 +204,7 @@ scanDirs (FcStrList *list, FcConfig *config, char *program, FcBool force, FcBool
set->nfont, nsubdirs (subdirs));
if (!FcDirCacheValid (dir))
if (!FcDirCacheUnlink (dir))
if (!FcDirCacheUnlink (dir, config))
ret++;
if (!FcDirSave (set, subdirs, dir))

View File

@ -205,7 +205,11 @@ FcCacheGlobalFileReadAndPrint (FcFontSet * set, FcStrSet *dirs, char *cache_file
if (!FcDirCacheConsume (fd, name_buf, set, 0))
goto bail1;
dir = strdup(name_buf);
dir = malloc (strlen (name_buf) + 2);
if (!dir)
goto bail1;
strcpy (dir, name_buf);
strcat (dir, "/");
FcCachePrintSet (set, dirs, dir);

View File

@ -282,7 +282,7 @@ FcBool
FcDirCacheHasCurrentArch (const FcChar8 *dir);
FcBool
FcDirCacheUnlink (const FcChar8 *dir);
FcDirCacheUnlink (const FcChar8 *dir, FcConfig *config);
/* fcblanks.c */
FcBlanks *

View File

@ -304,6 +304,7 @@ FcGlobalCacheReadDir (FcFontSet *set, FcStrSet *dirs, FcGlobalCache * cache, con
if (cache->fd == -1)
return FcFalse;
dir = (char *)FcConfigNormalizeFontDir (config, (FcChar8 *)dir);
for (d = cache->dirs; d; d = d->next)
{
if (strncmp (d->name, dir, strlen(dir)) == 0)
@ -322,10 +323,12 @@ FcGlobalCacheReadDir (FcFontSet *set, FcStrSet *dirs, FcGlobalCache * cache, con
FcBool
FcGlobalCacheUpdate (FcGlobalCache *cache,
const char *name,
FcFontSet *set)
FcFontSet *set,
FcConfig *config)
{
FcGlobalCacheDir * d;
name = (char *)FcConfigNormalizeFontDir (config, (FcChar8 *)name);
for (d = cache->dirs; d; d = d->next)
{
if (strcmp(d->name, name) == 0)
@ -351,7 +354,8 @@ FcGlobalCacheUpdate (FcGlobalCache *cache,
FcBool
FcGlobalCacheSave (FcGlobalCache *cache,
const FcChar8 *cache_file)
const FcChar8 *cache_file,
FcConfig *config)
{
int fd, fd_orig;
FcGlobalCacheDir *dir;
@ -425,7 +429,9 @@ FcGlobalCacheSave (FcGlobalCache *cache,
{
if (dir->name)
{
FcCacheWriteString (fd, dir->name);
const char * d = (const char *)FcConfigNormalizeFontDir (config, (const FcChar8 *)dir->name);
FcCacheWriteString (fd, d);
write (fd, &dir->metadata, sizeof(FcCache));
lseek (fd, FcCacheNextOffset (lseek(fd, 0, SEEK_CUR)), SEEK_SET);
write (fd, dir->ent, dir->metadata.count);
@ -649,14 +655,16 @@ FcDirCacheHasCurrentArch (const FcChar8 *dir)
}
FcBool
FcDirCacheUnlink (const FcChar8 *dir)
FcDirCacheUnlink (const FcChar8 *dir, FcConfig *config)
{
char *cache_file = (char *)FcStrPlus (dir, (FcChar8 *) "/" FC_DIR_CACHE_FILE);
char *cache_file;
char *cache_hashed;
int fd, collisions;
struct stat cache_stat;
char name_buf[FC_MAX_FILE_LEN];
dir = FcConfigNormalizeFontDir (config, dir);
cache_file = (char *)FcStrPlus (dir, (FcChar8 *) "/" FC_DIR_CACHE_FILE);
if (!cache_file)
return FcFalse;
@ -878,6 +886,7 @@ FcDirCacheOpen (const FcChar8 *dir)
if (stat ((char *)dir, &dir_stat) == -1)
return -1;
found = FcFalse;
do
{
struct stat c;

View File

@ -325,7 +325,7 @@ FcConfigBuildFonts (FcConfig *config)
FcFontSetPrint (fonts);
if (config->cache)
FcGlobalCacheSave (cache, config->cache);
FcGlobalCacheSave (cache, config->cache, config);
FcGlobalCacheDestroy (cache);
FcStrSetDestroy (oldDirs);
@ -394,18 +394,19 @@ FcConfigNormalizeFontDir (FcConfig *config,
{
/* If this is a bottleneck, we can cache the fontDir inodes. */
ino_t di;
dev_t dd;
int n;
struct stat s;
if (stat ((char *)d, &s) == -1)
return 0;
di = s.st_ino;
di = s.st_ino; dd = s.st_dev;
for (n = 0; n < config->fontDirs->num; n++)
{
if (stat ((char *)config->fontDirs->strs[n], &s) == -1)
continue;
if (di == s.st_ino)
if (di == s.st_ino && dd == s.st_dev)
return config->fontDirs->strs[n];
}
return 0;

View File

@ -188,7 +188,7 @@ FcDirScanConfig (FcFontSet *set,
* add the cache entry
*/
if (ret && cache)
FcGlobalCacheUpdate (cache, (char *)dir, tmpSet);
FcGlobalCacheUpdate (cache, (char *)dir, tmpSet, config);
for (i = 0; i < tmpSet->nfont; i++)
FcFontSetAdd (set, tmpSet->fonts[i]);

View File

@ -448,11 +448,13 @@ FcGlobalCacheLoad (FcGlobalCache *cache,
FcBool
FcGlobalCacheUpdate (FcGlobalCache *cache,
const char *file,
FcFontSet *set);
FcFontSet *set,
FcConfig *config);
FcBool
FcGlobalCacheSave (FcGlobalCache *cache,
const FcChar8 *cache_file);
const FcChar8 *cache_file,
FcConfig *config);
FcFontSet *
FcCacheRead (FcConfig *config, FcGlobalCache * cache);