[Fontconfig-bugs] [Bug 101889] Make fontconfig cache relocatable

bugzilla-daemon at freedesktop.org bugzilla-daemon at freedesktop.org
Thu Aug 31 13:45:03 UTC 2017


https://bugs.freedesktop.org/show_bug.cgi?id=101889

--- Comment #29 from Alexander Larsson <alexl at redhat.com> ---
Ok, lets start from scratch, defining the requirements.

On the host side, there is a set of system font directories, and one
system font cache directory. For example /usr/share/fonts/* and
/usr/lib/fontconfig/cache/

The cache is rebuilt when the font directory changed. However, this
may be running on the actual host (old-school) or when building the
read-only image (fedora atomic).

The cache stores the time of the font directory, which can be used to
validate it on use-time. In the read-only image case the font
directory mtime is set to zero before the cache is generated, and when
installed to disk (both atomic and flatpak does this).

This works in many cases:
 * On the host, when rebuilding the cache locally in in post-install
 * On the host, in the read-only image case (due to the mtime hack)
 * In flatpak for the font directories and font caches that are
   shipped per-generated (with 0 mtime) in the runtime.

However, we want to add a new case: exposing the host font directory
to the flatpak (in addition to the fonts in the flatpak runtime).

This is set up in the following way in the sandbox:
 /usr/share/fonts is from the runtime
 /usr/lib/fontconfig/cache/ is from the runtime
 /run/host/fonts is a bind-mount of the host fonts dir
 /run/host/fonts-cache is a bind-mount of the host font cache dir
 /etc/fonts/fonts.conf is from the runtime, adds all the above dirs

Here we run into issues. When loading a font from /run/host/fonts, if
we look up the cache by checksum("/run/host/fonts") we will not find
the correct cache, even though it is visible and configured in
/run/host/fonts-cache. The alternative is to look up the font by
checksum(ino,dev), however, that will not work when looking up in
/usr/share/fonts from the runtime, because we don't know the final
dev:ino when creating the cache.

One possible solution would be to make fc-scan generate both kinds of
hashes (make the dev+inode cache a symlink to the real cache). Then we
can specify in the config file what type of lookup to do on each cache
dir. The flatpak runtime config would have:

        <cachedir type="devino">/run/host/fonts-cache</cachedir>

This would make lookups of of fonts work both on the host and in
flatpak, and additionally we would never accidentally do pathname
based lookups of the host fonts from the sandbox.

There is one combination where this would break though. If you are
running fedora atomic on the host, then the pre-generated cache in the
host /usr/lib/fontconfig/cache will not contain devinode info (or it
will be wrong), and flatpak will not be able to read it.

There is another approach though. Instead of using the device+inode to
look up the cache we use a separate file. It would go like this:

 if $fontdir/.uuid exists:
   look up cache based on content-of($fontdir/.uuid)
 else
   look up cache based on path-of($fontdir)

Then we make fc-scan create a random .uuid file if one does not exist.
This would happen in the post-inst in the traditional case, but it
would instead happen during image-building in the fedora atomic and
flatpak runtime case. In this model we wouldn't need to set the cache
dir lookup style in the config file.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/fontconfig-bugs/attachments/20170831/7212583b/attachment.html>


More information about the Fontconfig-bugs mailing list