+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>
* fc-cache/fc-cache.c (scanDirs):
* fc-cat/fc-cat.c (FcCacheGlobalFileReadAndPrint, FcCacheFileRead):
#define MACHINE_SIGNATURE_SIZE 9 + 5*20 + 1
static int
-FcDirCacheOpen (char * cache_file);
+FcDirCacheOpen (const FcChar8 * dir);
static char *
FcDirCacheHashName (char * cache_file, int collisions);
FcBool
FcDirCacheValid (const FcChar8 *dir)
{
- FcChar8 *cache_file;
struct stat file_stat, dir_stat;
int fd;
if (stat ((char *) dir, &dir_stat) < 0)
return FcFalse;
- cache_file = FcStrPlus (dir, (FcChar8 *) "/" FC_DIR_CACHE_FILE);
- if (!cache_file)
- return FcFalse;
-
- fd = FcDirCacheOpen ((char *)cache_file);
+ fd = FcDirCacheOpen (dir);
if (fd < 0)
goto bail;
if (fstat (fd, &file_stat) < 0)
- goto bail1;
+ goto bail;
close (fd);
- FcStrFree (cache_file);
/*
* If the directory has been modified more recently than
return FcTrue;
- bail1:
- close (fd);
bail:
- FcStrFree (cache_file);
+ close (fd);
return FcFalse;
}
FcBool
FcDirCacheHasCurrentArch (const FcChar8 *dir)
{
- char *cache_file;
int fd;
off_t current_arch_start;
char *current_arch_machine_name;
- cache_file = (char *)FcStrPlus (dir, (FcChar8 *) "/" FC_DIR_CACHE_FILE);
- if (!cache_file)
- return FcFalse;
-
- fd = FcDirCacheOpen (cache_file);
+ fd = FcDirCacheOpen (dir);
if (fd < 0)
goto bail;
return FcTrue;
bail:
- free (cache_file);
return FcFalse;
}
struct stat cache_stat;
char name_buf[FC_MAX_FILE_LEN];
+ if (!cache_file)
+ return FcFalse;
+
/* First remove normal cache file. */
if (stat ((char *) cache_file, &cache_stat) == 0 &&
unlink ((char *)cache_file) != 0)
* This would fail in the unlikely event of a collision and subsequent
* removal of the file which originally caused the collision. */
static int
-FcDirCacheOpen (char *cache_file)
+FcDirCacheOpen (const FcChar8 *dir)
{
+ FcBool found;
int fd = -1, collisions = 0;
- char *cache_hashed;
+ char *cache_file, *cache_hashed;
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);
if (fd != -1)
return fd;
+ if (stat ((char *)dir, &dir_stat) == -1)
+ return -1;
+
do
{
+ struct stat c;
+ FcChar8 * name_buf_dir;
+
cache_hashed = FcDirCacheHashName (cache_file, collisions++);
if (!cache_hashed)
return -1;
FcCacheReadString (fd, name_buf, sizeof (name_buf));
if (!strlen(name_buf))
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;
bail:
FcBool
FcDirCacheRead (FcFontSet * set, FcStrSet * dirs, const FcChar8 *dir, FcConfig *config)
{
- char *cache_file;
int fd;
char *current_arch_machine_name;
char candidate_arch_machine_name[9+MACHINE_SIGNATURE_SIZE];
off_t current_arch_start = 0;
char subdirName[FC_MAX_FILE_LEN + 1 + 12 + 1];
- cache_file = (char *)FcStrPlus (dir, (FcChar8 *) "/" FC_DIR_CACHE_FILE);
- if (!cache_file)
- return FcFalse;
-
- fd = FcDirCacheOpen (cache_file);
+ fd = FcDirCacheOpen (dir);
if (fd < 0)
goto bail;
goto bail1;
close(fd);
- free (cache_file);
return FcTrue;
bail1:
close (fd);
bail:
- free (cache_file);
return FcFalse;
}
{
pos = FcCacheNextOffset (lseek(fd, 0, SEEK_CUR));
lseek (fd, pos, SEEK_SET);
+ FcConfigAddFontDir (config, (FcChar8 *)dir);
return FcTrue;
}