static void
FcGlobalCacheDirDestroy (FcGlobalCacheDir *d)
{
+ FcStrSetDestroy (d->subdirs);
FcMemFree (FC_MEM_STRING, strlen (d->name)+1);
free (d->name);
FcMemFree (FC_MEM_CACHE, sizeof (FcGlobalCacheDir));
off_t current_arch_start;
struct stat cache_stat, dir_stat;
+ char subdirName[FC_MAX_FILE_LEN + 1 + 12 + 1];
if (stat ((char *) cache_file, &cache_stat) < 0)
return;
cache->updated = FcFalse;
- FcCacheReadString (cache->fd, name_buf, sizeof (name_buf));
+ if (!FcCacheReadString (cache->fd, name_buf, sizeof (name_buf)))
+ return;
if (strcmp (name_buf, FC_GLOBAL_MAGIC_COOKIE) != 0)
return;
goto bail_and_destroy;
lseek (cache->fd, current_arch_start, SEEK_SET);
- FcCacheReadString (cache->fd, candidate_arch_machine_name,
- sizeof (candidate_arch_machine_name));
+ if (!FcCacheReadString (cache->fd, candidate_arch_machine_name,
+ sizeof (candidate_arch_machine_name)))
+ goto bail_and_destroy;
if (strlen(candidate_arch_machine_name) == 0)
goto bail_and_destroy;
{
off_t targ;
- FcCacheReadString (cache->fd, name_buf, sizeof (name_buf));
- if (!strlen(name_buf))
+ if (!FcCacheReadString (cache->fd, name_buf, sizeof (name_buf)) || !strlen(name_buf))
break;
/* Directory must be older than the global cache file; also
d->name = (char *)FcStrCopy ((FcChar8 *)name_buf);
d->ent = 0;
d->offset = lseek (cache->fd, 0, SEEK_CUR);
+
+ d->subdirs = FcStrSetCreate();
+ while (strlen(FcCacheReadString (cache->fd, subdirName, sizeof (subdirName))) > 0)
+ FcStrSetAdd (d->subdirs, (FcChar8 *)subdirName);
+
if (read (cache->fd, &d->metadata, sizeof (FcCache)) != sizeof (FcCache))
goto bail1;
targ = FcCacheNextOffset (lseek(cache->fd, 0, SEEK_CUR)) + d->metadata.count;
if (cache->fd == -1)
return FcFalse;
- dir = (char *)FcConfigNormalizeFontDir (config, (FcChar8 *)dir);
+ if (!(dir = (char *)FcConfigNormalizeFontDir (config, (FcChar8 *)dir)))
+ return FcFalse; /* non-existing directory */
+
for (d = cache->dirs; d; d = d->next)
{
if (strncmp (d->name, dir, strlen(dir)) == 0)
{
lseek (cache->fd, d->offset, SEEK_SET);
- if (!FcDirCacheConsume (cache->fd, dir, set, config))
+ if (!FcDirCacheConsume (cache->fd, d->name, set, config))
return FcFalse;
if (strcmp (d->name, dir) == 0)
ret = FcTrue;
FcBool
FcGlobalCacheUpdate (FcGlobalCache *cache,
+ FcStrSet *dirs,
const char *name,
FcFontSet *set,
FcConfig *config)
{
- FcGlobalCacheDir * d;
+ FcGlobalCacheDir *d;
+ int i;
name = (char *)FcConfigNormalizeFontDir (config, (FcChar8 *)name);
for (d = cache->dirs; d; d = d->next)
d->name = (char *)FcStrCopy ((FcChar8 *)name);
d->ent = FcDirCacheProduce (set, &d->metadata);
d->offset = 0;
+ d->subdirs = FcStrSetCreate();
+ for (i = 0; i < dirs->num; i++)
+ FcStrSetAdd (d->subdirs, dirs->strs[i]);
return FcTrue;
}
const FcChar8 *cache_file,
FcConfig *config)
{
- int fd, fd_orig;
+ int fd, fd_orig, i;
FcGlobalCacheDir *dir;
FcAtomic *atomic;
off_t current_arch_start = 0, truncate_to;
S_IRUSR | S_IWUSR);
if (fd == -1)
goto bail2;
+ FcCacheWriteString (fd, FC_GLOBAL_MAGIC_COOKIE);
fd_orig = open ((char *) FcAtomicOrigFile(atomic), O_RDONLY);
current_arch_machine_name);
if (current_arch_start < 0)
- current_arch_start = FcCacheNextOffset (lseek(fd_orig, 0, SEEK_END));
+ {
+ off_t i = lseek(fd_orig, 0, SEEK_END);
+ if (i < strlen (FC_GLOBAL_MAGIC_COOKIE)+1)
+ i = strlen (FC_GLOBAL_MAGIC_COOKIE)+1;
+ current_arch_start = FcCacheNextOffset (i);
+ }
if (!FcCacheCopyOld(fd, fd_orig, current_arch_start))
goto bail3;
truncate_to += sizeof (FcCache);
truncate_to = FcCacheNextOffset (truncate_to);
truncate_to += dir->metadata.count;
+
+ for (i = 0; i < dir->subdirs->size; i++)
+ truncate_to += strlen((char *)dir->subdirs->strs[i]) + 1;
+ truncate_to ++;
}
truncate_to -= current_arch_start;
- FcCacheWriteString (fd, FC_GLOBAL_MAGIC_COOKIE);
sprintf (header, "%8x ", (int)truncate_to);
strcat (header, current_arch_machine_name);
if (!FcCacheWriteString (fd, header))
const char * d = (const char *)FcConfigNormalizeFontDir (config, (const FcChar8 *)dir->name);
FcCacheWriteString (fd, d);
+
+ for (i = 0; i < dir->subdirs->size; i++)
+ FcCacheWriteString (fd, (char *)dir->subdirs->strs[i]);
+ FcCacheWriteString (fd, "");
+
write (fd, &dir->metadata, sizeof(FcCache));
lseek (fd, FcCacheNextOffset (lseek(fd, 0, SEEK_CUR)), SEEK_SET);
write (fd, dir->ent, dir->metadata.count);
FcDirCacheUnlink (const FcChar8 *dir, FcConfig *config)
{
char *cache_file;
- char *cache_hashed;
+ char *cache_hashed = 0;
int fd, collisions;
struct stat cache_stat;
char name_buf[FC_MAX_FILE_LEN];
fd = -1; collisions = 0;
do
{
+ if (cache_hashed)
+ FcStrFree ((FcChar8 *)cache_hashed);
+
cache_hashed = FcDirCacheHashName (cache_file, collisions++);
if (!cache_hashed)
goto bail;
return FcTrue;
}
- FcCacheReadString (fd, name_buf, sizeof (name_buf));
- if (!strlen(name_buf))
+ if (!FcCacheReadString (fd, name_buf, sizeof (name_buf)) || !strlen(name_buf))
+ {
+ FcStrFree ((FcChar8 *)cache_hashed);
goto bail;
+ }
} while (strcmp (name_buf, cache_file) != 0);
FcStrFree ((FcChar8 *)cache_file);
cache_hashed = FcDirCacheHashName (cache_file, collisions++);
if (!cache_hashed)
+ {
+ FcStrFree ((FcChar8 *)cache_file);
return -1;
+ }
if (fd > 0)
close (fd);
FcStrFree ((FcChar8 *)cache_hashed);
if (fd == -1)
+ {
+ FcStrFree ((FcChar8 *)cache_file);
return -1;
- FcCacheReadString (fd, name_buf, sizeof (name_buf));
- if (!strlen(name_buf))
+ }
+ if (!FcCacheReadString (fd, name_buf, sizeof (name_buf)) || !strlen(name_buf))
goto bail;
name_buf_dir = FcStrDirname ((FcChar8 *)name_buf);
continue;
}
FcStrFree (name_buf_dir);
- found = c.st_ino == dir_stat.st_ino;
+ found = (c.st_ino == dir_stat.st_ino) && (c.st_dev == dir_stat.st_dev);
} while (!found);
+ FcStrFree ((FcChar8 *)cache_file);
return fd;
bail:
+ FcStrFree ((FcChar8 *)cache_file);
close (fd);
return -1;
}
sizeof (candidate_arch_machine_name)) == 0)
goto bail1;
- while (strlen(FcCacheReadString (fd, subdirName, sizeof (subdirName))) > 0)
+ while (FcCacheReadString (fd, subdirName, sizeof (subdirName)) && strlen (subdirName) > 0)
FcStrSetAdd (dirs, (FcChar8 *)subdirName);
if (!FcDirCacheConsume (fd, (const char *)dir, set, config))
{
pos = FcCacheNextOffset (lseek(fd, 0, SEEK_CUR));
lseek (fd, pos, SEEK_SET);
- FcConfigAddFontDir (config, (FcChar8 *)dir);
+ if (config)
+ FcConfigAddFontDir (config, (FcChar8 *)dir);
return FcTrue;
}
fd = open(cache_hashed, O_RDONLY);
if (fd == -1)
break;
- FcCacheReadString (fd, name_buf, sizeof (name_buf));
- close (fd);
-
- if (!strlen(name_buf))
+ if(!FcCacheReadString (fd, name_buf, sizeof (name_buf)) || !strlen(name_buf))
+ {
+ close (fd);
break;
+ }
+ close (fd);
if (strcmp (name_buf, cache_file) != 0)
continue;
FcCacheSkipToArch(fd_orig, current_arch_machine_name);
if (current_arch_start < 0)
- current_arch_start = FcCacheNextOffset (lseek(fd_orig, 0, SEEK_END));
+ {
+ off_t i = lseek(fd_orig, 0, SEEK_END);
+ if (i < strlen (FC_GLOBAL_MAGIC_COOKIE)+1)
+ i = strlen (FC_GLOBAL_MAGIC_COOKIE)+1;
+ current_arch_start = FcCacheNextOffset (i);
+ }
if (fd_orig != -1 && !FcCacheCopyOld(fd, fd_orig, current_arch_start))
goto bail4;
if (ftruncate (fd, current_arch_start + truncate_to) == -1)
goto bail5;
+ free (header);
close(fd);
if (!FcAtomicReplaceOrig(atomic))
goto bail5;
FcStrFree ((FcChar8 *)cache_hashed);
+ FcStrFree ((FcChar8 *)cache_file);
FcAtomicUnlock (atomic);
FcAtomicDestroy (atomic);
return FcTrue;
FcStrFree ((FcChar8 *)cache_hashed);
bail0:
unlink ((char *)cache_file);
- free (cache_file);
+ FcStrFree ((FcChar8 *)cache_file);
if (current_dir_block)
free (current_dir_block);
bail: