[Fontconfig] Patch (was: fc-cache for x86 deletes caches for x86_64)

Mike FABIAN mfabian at suse.de
Tue Oct 24 08:36:03 PDT 2006


Mike FABIAN <mfabian at suse.de> さんは書きました:

> Now run the 32-bit version of fc-cache:
>
>     mfabian at magellan:~$ fc-cache32 -v /usr/share/fonts/truetype
>     /usr/share/fonts/truetype: caching, 911 fonts, 0 dirs
>     /var/cache/fontconfig: not cleaning unwritable cache directory
>     /home/mfabian/.fontconfig: cleaning cache directory
>     /home/mfabian/.fontconfig: 7ef2298fde41cc6eeb7af42e48b7d293-x86-64.cache-2: missing directory: ú¼ Šfc-cache32: succeeded
>     mfabian at magellan:~$
>
> There was a strange error message at the end.
> And the 64-bit cache is gone now:
>
>     mfabian at magellan:~$ ls /var/cache/fontconfig/
>     mfabian at magellan:~$ ls .fontconfig
>     7ef2298fde41cc6eeb7af42e48b7d293-x86.cache-2
>     mfabian at magellan:~$ 
>
> That's not right, fc-cache should not touch the cache files
> for different architectures.

The reason why fc-cache32 deletes the x86-64 cache files
but the 64 bit fc-cache doesn't delete the x86 cache files
is as follows:

In case of fc-cache32, line 313

	cache = FcDirCacheLoadFile (file_name, &file_stat);

in fc-cache.c happens to be successful. But then fc-cache32
cannot read the directory out of the x86-64 cache file
i.e.

	target_dir = FcCacheDir (cache);
	remove = FcFalse;
	if (stat ((char *) target_dir, &target_stat) < 0)
	{
	    if (verbose)
		printf ("%s: %s: missing directory: %s \n",
			dir, ent->d_name, target_dir);
	    remove = FcTrue;
	}

leads to the removal of the x86-64 cache file.

In case of the 64 bit fc-cache,

	cache = FcDirCacheLoadFile (file_name, &file_stat);

already fails because of line 467 in fccache.c
(function FcDirCacheMapFd ()):

	cache->size != fd_stat->st_size ||

cache->size is of type intptr_t which is 8 bytes on x86-64
but only 4 bytes on x86. Therefore, the 64 bit fc-cache reads 4 bytes
containing the file size plus another 4 bytes of junk and interprets
this as the file size:

struct _FcCache {
    int		magic;              /* FC_CACHE_MAGIC_MMAP or FC_CACHE_ALLOC */
    int		version;	    /* FC_CACHE_CONTENT_VERSION */
    intptr_t	size;		    /* size of file */
    intptr_t	dir;		    /* offset to dir name */
    intptr_t	dirs;		    /* offset to subdirs */
    int		dirs_count;	    /* number of subdir strings */
    intptr_t	set;		    /* offset to font set */
};

But even then one gets the annoying message

    fprintf (stderr, "%s: invalid cache file: %s\n", dir, ent->d_name);

for each -x86.cache-2 file. This makes no sense because it is
OK that cache files for other architectures are there.

I tried to fix the problem with the attached patch which
seems to work for me.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: do-not-clean-cache-files-for-different-architectures.patch
Type: text/x-patch
Size: 729 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/fontconfig/attachments/20061024/20867f3d/do-not-clean-cache-files-for-different-architectures.bin
-------------- next part --------------

-- 
Mike FABIAN   <mfabian at suse.de>   http://www.suse.de/~mfabian
睡眠不足はいい仕事の敵だ。


More information about the Fontconfig mailing list