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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Mike FABIAN <mfabian@xxxxxxx> さんは書きました:

> Now run the 32-bit version of fc-cache:
>
>     mfabian@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@magellan:~$
>
> There was a strange error message at the end.
> And the 64-bit cache is gone now:
>
>     mfabian@magellan:~$ ls /var/cache/fontconfig/
>     mfabian@magellan:~$ ls .fontconfig
>     7ef2298fde41cc6eeb7af42e48b7d293-x86.cache-2
>     mfabian@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.

diff -ru fontconfig-2.4.1.orig/fc-cache/fc-cache.c fontconfig-2.4.1/fc-cache/fc-cache.c
--- fontconfig-2.4.1.orig/fc-cache/fc-cache.c	2006-09-14 03:53:49.000000000 +0200
+++ fontconfig-2.4.1/fc-cache/fc-cache.c	2006-10-24 16:50:35.000000000 +0200
@@ -22,6 +22,8 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
+#include "../fc-arch/fcarch.h"
+
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #else
@@ -296,6 +298,11 @@
 
 	if (ent->d_name[0] == '.')
 	    continue;
+	/* skip cache files for different architectures and */
+	/* files which are not cache files at all */
+	if (!strstr(ent->d_name, "-" FC_ARCHITECTURE FC_CACHE_SUFFIX))
+	    continue;
+	
 	file_name = FcStrPlus (dir_base, (FcChar8 *) ent->d_name);
 	if (!file_name)
 	{
-- 
Mike FABIAN   <mfabian@xxxxxxx>   http://www.suse.de/~mfabian
睡眠不足はいい仕事の敵だ。
_______________________________________________
Fontconfig mailing list
Fontconfig@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/fontconfig

[Index of Archives]     [Fedora Fonts]     [Fedora Users]     [Fedora Cloud]     [Kernel]     [Fedora Packaging]     [Fedora Desktop]     [PAM]     [Gimp Graphics Editor]     [Yosemite News]

  Powered by Linux