Explicitly add font dirs to config.fontDirs even if they're empty. Set

current config in fc-cache.c. Fix treatment of cache directory as read
    from cache file; don't use string equality to determine if we have the
    right file, use inode equality.
This commit is contained in:
Patrick Lam 2006-01-10 13:15:05 +00:00
parent cd9bca6970
commit df3efc11a9
3 changed files with 47 additions and 30 deletions

View File

@ -1,3 +1,15 @@
2006-01-10 Patrick Lam <plam@mit.edu>
* src/fccache.c (FcDirCacheConsume, FcDirCacheOpen,
FcDirCacheValid, FcDirCacheHasCurrentArch,
FcDirCacheUnlink, FcDirCacheRead, FcDirCacheConsume):
* fc-cache/fc-cache.c (main):
Explicitly add font dirs to config.fontDirs even if they're empty.
Set current config in fc-cache.c.
Fix treatment of cache directory as read from cache file; don't
use string equality to determine if we have the right file,
use inode equality.
2006-01-09 Patrick Lam <plam@mit.edu> 2006-01-09 Patrick Lam <plam@mit.edu>
* fc-cache/fc-cache.c (scanDirs): * fc-cache/fc-cache.c (scanDirs):
* fc-cat/fc-cat.c (FcCacheGlobalFileReadAndPrint, FcCacheFileRead): * fc-cat/fc-cat.c (FcCacheGlobalFileReadAndPrint, FcCacheFileRead):

View File

@ -281,6 +281,7 @@ main (int argc, char **argv)
fprintf (stderr, "%s: Can't init font config library\n", argv[0]); fprintf (stderr, "%s: Can't init font config library\n", argv[0]);
return 1; return 1;
} }
FcConfigSetCurrent (config);
if (argv[i]) if (argv[i])
{ {

View File

@ -37,7 +37,7 @@
#define MACHINE_SIGNATURE_SIZE 9 + 5*20 + 1 #define MACHINE_SIGNATURE_SIZE 9 + 5*20 + 1
static int static int
FcDirCacheOpen (char * cache_file); FcDirCacheOpen (const FcChar8 * dir);
static char * static char *
FcDirCacheHashName (char * cache_file, int collisions); FcDirCacheHashName (char * cache_file, int collisions);
@ -593,26 +593,20 @@ FcCacheCopyOld (int fd, int fd_orig, off_t start)
FcBool FcBool
FcDirCacheValid (const FcChar8 *dir) FcDirCacheValid (const FcChar8 *dir)
{ {
FcChar8 *cache_file;
struct stat file_stat, dir_stat; struct stat file_stat, dir_stat;
int fd; int fd;
if (stat ((char *) dir, &dir_stat) < 0) if (stat ((char *) dir, &dir_stat) < 0)
return FcFalse; return FcFalse;
cache_file = FcStrPlus (dir, (FcChar8 *) "/" FC_DIR_CACHE_FILE); fd = FcDirCacheOpen (dir);
if (!cache_file)
return FcFalse;
fd = FcDirCacheOpen ((char *)cache_file);
if (fd < 0) if (fd < 0)
goto bail; goto bail;
if (fstat (fd, &file_stat) < 0) if (fstat (fd, &file_stat) < 0)
goto bail1; goto bail;
close (fd); close (fd);
FcStrFree (cache_file);
/* /*
* If the directory has been modified more recently than * If the directory has been modified more recently than
@ -623,10 +617,8 @@ FcDirCacheValid (const FcChar8 *dir)
return FcTrue; return FcTrue;
bail1:
close (fd);
bail: bail:
FcStrFree (cache_file); close (fd);
return FcFalse; return FcFalse;
} }
@ -635,16 +627,11 @@ FcDirCacheValid (const FcChar8 *dir)
FcBool FcBool
FcDirCacheHasCurrentArch (const FcChar8 *dir) FcDirCacheHasCurrentArch (const FcChar8 *dir)
{ {
char *cache_file;
int fd; int fd;
off_t current_arch_start; off_t current_arch_start;
char *current_arch_machine_name; char *current_arch_machine_name;
cache_file = (char *)FcStrPlus (dir, (FcChar8 *) "/" FC_DIR_CACHE_FILE); fd = FcDirCacheOpen (dir);
if (!cache_file)
return FcFalse;
fd = FcDirCacheOpen (cache_file);
if (fd < 0) if (fd < 0)
goto bail; goto bail;
@ -658,7 +645,6 @@ FcDirCacheHasCurrentArch (const FcChar8 *dir)
return FcTrue; return FcTrue;
bail: bail:
free (cache_file);
return FcFalse; return FcFalse;
} }
@ -671,6 +657,9 @@ FcDirCacheUnlink (const FcChar8 *dir)
struct stat cache_stat; struct stat cache_stat;
char name_buf[FC_MAX_FILE_LEN]; char name_buf[FC_MAX_FILE_LEN];
if (!cache_file)
return FcFalse;
/* First remove normal cache file. */ /* First remove normal cache file. */
if (stat ((char *) cache_file, &cache_stat) == 0 && if (stat ((char *) cache_file, &cache_stat) == 0 &&
unlink ((char *)cache_file) != 0) unlink ((char *)cache_file) != 0)
@ -870,18 +859,30 @@ FcDirCacheHashName (char * cache_file, int collisions)
* This would fail in the unlikely event of a collision and subsequent * This would fail in the unlikely event of a collision and subsequent
* removal of the file which originally caused the collision. */ * removal of the file which originally caused the collision. */
static int static int
FcDirCacheOpen (char *cache_file) FcDirCacheOpen (const FcChar8 *dir)
{ {
FcBool found;
int fd = -1, collisions = 0; int fd = -1, collisions = 0;
char *cache_hashed; char *cache_file, *cache_hashed;
char name_buf[FC_MAX_FILE_LEN]; char name_buf[FC_MAX_FILE_LEN];
struct stat dir_stat;
cache_file = (char *)FcStrPlus (dir, (FcChar8 *) "/" FC_DIR_CACHE_FILE);
if (!cache_file)
return -1;
fd = open(cache_file, O_RDONLY); fd = open(cache_file, O_RDONLY);
if (fd != -1) if (fd != -1)
return fd; return fd;
if (stat ((char *)dir, &dir_stat) == -1)
return -1;
do do
{ {
struct stat c;
FcChar8 * name_buf_dir;
cache_hashed = FcDirCacheHashName (cache_file, collisions++); cache_hashed = FcDirCacheHashName (cache_file, collisions++);
if (!cache_hashed) if (!cache_hashed)
return -1; return -1;
@ -896,7 +897,16 @@ FcDirCacheOpen (char *cache_file)
FcCacheReadString (fd, name_buf, sizeof (name_buf)); FcCacheReadString (fd, name_buf, sizeof (name_buf));
if (!strlen(name_buf)) if (!strlen(name_buf))
goto bail; goto bail;
} while (strcmp (name_buf, cache_file) != 0);
name_buf_dir = FcStrDirname ((FcChar8 *)name_buf);
if (stat ((char *)name_buf_dir, &c) == -1)
{
FcStrFree (name_buf_dir);
continue;
}
FcStrFree (name_buf_dir);
found = c.st_ino == dir_stat.st_ino;
} while (!found);
return fd; return fd;
bail: bail:
@ -908,18 +918,13 @@ FcDirCacheOpen (char *cache_file)
FcBool FcBool
FcDirCacheRead (FcFontSet * set, FcStrSet * dirs, const FcChar8 *dir, FcConfig *config) FcDirCacheRead (FcFontSet * set, FcStrSet * dirs, const FcChar8 *dir, FcConfig *config)
{ {
char *cache_file;
int fd; int fd;
char *current_arch_machine_name; char *current_arch_machine_name;
char candidate_arch_machine_name[9+MACHINE_SIGNATURE_SIZE]; char candidate_arch_machine_name[9+MACHINE_SIGNATURE_SIZE];
off_t current_arch_start = 0; off_t current_arch_start = 0;
char subdirName[FC_MAX_FILE_LEN + 1 + 12 + 1]; char subdirName[FC_MAX_FILE_LEN + 1 + 12 + 1];
cache_file = (char *)FcStrPlus (dir, (FcChar8 *) "/" FC_DIR_CACHE_FILE); fd = FcDirCacheOpen (dir);
if (!cache_file)
return FcFalse;
fd = FcDirCacheOpen (cache_file);
if (fd < 0) if (fd < 0)
goto bail; goto bail;
@ -941,13 +946,11 @@ FcDirCacheRead (FcFontSet * set, FcStrSet * dirs, const FcChar8 *dir, FcConfig *
goto bail1; goto bail1;
close(fd); close(fd);
free (cache_file);
return FcTrue; return FcTrue;
bail1: bail1:
close (fd); close (fd);
bail: bail:
free (cache_file);
return FcFalse; return FcFalse;
} }
@ -966,6 +969,7 @@ FcDirCacheConsume (int fd, const char * dir, FcFontSet *set, FcConfig *config)
{ {
pos = FcCacheNextOffset (lseek(fd, 0, SEEK_CUR)); pos = FcCacheNextOffset (lseek(fd, 0, SEEK_CUR));
lseek (fd, pos, SEEK_SET); lseek (fd, pos, SEEK_SET);
FcConfigAddFontDir (config, (FcChar8 *)dir);
return FcTrue; return FcTrue;
} }