Bug 97240 - xfs unnesessarily rebuilding fonts.dir due to fonts.cache-1
xfs unnesessarily rebuilding fonts.dir due to fonts.cache-1
Status: CLOSED RAWHIDE
Product: Red Hat Raw Hide
Classification: Retired
Component: XFree86 (Show other bugs)
1.0
All Linux
medium Severity medium
: ---
: ---
Assigned To: Mike A. Harris
David Lawrence
:
Depends On:
Blocks: CambridgeTarget
  Show dependency treegraph
 
Reported: 2003-06-11 16:35 EDT by Rex Dieter
Modified: 2007-04-18 12:54 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2003-10-11 05:08:07 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Rex Dieter 2003-06-11 16:35:30 EDT
Description of problem:  
xfs sometimes unessarily rebuilds fonts.dir only because of the presences of a  
newer fonts.cache-1 file, not for any actual new fonts.  
  
Version-Release number of selected component (if applicable): XFree-4.3.0-15  
  
Patch to xfs.init to ignore the presence of fonts.cache-1 file:  
34c34  
<          elif [ "$(find . -type f -cnewer fonts.dir 2>/dev/null)" != "" ];then  
---  
>          elif [ "$(find . -type f -not -name fonts.cache-1 -cnewer fonts.dir  
2>/dev/null)" != "" ];then
Comment 1 Mike A. Harris 2003-10-08 21:05:30 EDT
Doh, this report fell between the cracks, however recent discussion brought
it back to my attention.  I've just commited a fix to xfs.init in the src.rpm
which is based on your above fix, but slightly more robust:

elif [ "$(find . -type f -cnewer fonts.dir -not -name "fonts.cache*"
>/dev/null)" != "" ];then

The fonts.cache filenames may change in future, so this will catch any changes.

Owen:  Is this sufficient, or is there some other enhancement you think would
be nice to include to speed up startup?

The current fix is in 4.3.0-37.1 and will be in the next rawhide build.
Comment 2 Owen Taylor 2003-10-08 22:31:12 EDT
As discussed in IRC yesterday, while the above is needed, it is
not sufficient. You also need to run fc-cache at least
every time you update a fonts.dir file, or any change to a font
directory will leave fontconfig permanently out of date.

The simplest way to do this is to *always* run fc-cache; it's quite
fast when there are no out-of-date font directories. Thaat is,
at the end of buildfontlist, add:

   done
+   # Recreating fonts.dir files above may result in stale fonts.cache-1
+   # files since the directory mtimes change, so we run fc-cache to
+   # update any necessary fonts.cache files.
+   [ -x /usr/bin/fc-cache ] && /usr/bin/fc-cache
   popd &> /dev/null

I tested this yesterday with a patch similar to what you had above
(fonts.cache*) and it worked well.

In your comment above, is the >/dev/null replaing 2>/dev/null just a typo?
It clearly won't won't work that way :-)
Comment 3 Mike A. Harris 2003-10-08 22:43:02 EDT
>The simplest way to do this is to *always* run fc-cache; it's quite
>fast when there are no out-of-date font directories. Thaat is,
>at the end of buildfontlist, add:

Ok, I'll add that, however I think the fontconfig package should have it's
own initscript also which does similar detection for cases where the user
disables our xfs initscript, either because they prefer to use the X server
to handle core fonts, or because they're using a networked font server.

That's something that we can do for the next development cycle if you agree
that it is a sane thing to do (which I hope <grin>).  The fc-cache being
in xfs initscript seems like a good idea regardless though, even if we
do have a fontconfig initscript.
Comment 4 Mike A. Harris 2003-10-08 22:45:29 EDT
I've added your fc-cache suggestion to the xfs.init script.

>In your comment above, is the >/dev/null replaing 2>/dev/null just a typo?
>It clearly won't won't work that way :-)

That was an inadvertent typo that got into the bugzilla comment when I added it
somehow.  The initscript has 2>/dev/null still.  ;o)
Comment 5 Mike A. Harris 2003-10-08 22:47:27 EDT
Here are all of the changes I made, which are awaiting peer review before
I officially commit all changes to the next build:

@@ -32,25 +32,29 @@
          NEEDED=no
          if ! [ -e fonts.dir ]; then
             NEEDED=yes
-         elif [ "$(find . -type f -cnewer fonts.dir 2>/dev/null)" != "" ];then
+         elif [ "$(find . -type f -cnewer fonts.dir -not -name "fonts.cache*"
2>/dev/null)" != "" ];then
             NEEDED=yes
          fi
          if [ "$NEEDED" = "yes" ]; then
             rm -f fonts.dir &>/dev/null
-            if ls | grep -i "\.tt[cf]$" &>/dev/null; then
-               # TrueType fonts found...
+            if ls | grep -i "\.[ot]t[cf]$" &>/dev/null; then
+               # TrueType or Opentype fonts found...
                ttmkfdir -d . -o fonts.scale
                mkfontdir . &>/dev/null
                [ -e fonts.dir ] && chmod 644 fonts.scale fonts.dir
             fi
-            if [ "$(ls |egrep -iv '\.tt[cf]$|^fonts\.|^encodings\.')" != "" ]; then
-               # This directory contains fonts that are not TrueType...
+            if [ "$(ls |grep -iv
'\(fonts\.\(scale\|alias\|cache.*\)$\|.+\(\.[ot]t[cf]\|dir\)$\)')" != "" ]; then
+               # This directory contains fonts that are not TrueType or Opentype...
                mkfontdir . &>/dev/null
                [ -e fonts.dir ] && chmod 644 fonts.dir
             fi
          fi
       fi
    done
+   # Recreating fonts.dir files above may result in stale fonts.cache-1
+   # files since the directory mtimes change, so we run fc-cache to
+   # update any necessary fonts.cache files.
+   [ -x /usr/bin/fc-cache ] && /usr/bin/fc-cache
    popd &> /dev/null
 }
Comment 6 Mike A. Harris 2003-10-08 22:54:39 EDT
Hmm, the final check will trigger mkfontdir to be called if the directory
contains a subdirectory.  Perhaps it should use "find . -type f -regex '....'"
instead of using ls | grep?  However the find command would have to limit it's
search to just the one directory and not subdirs otherwise new files found in
subdirs would trigger fonts.dir recreation in the current dir also.  Kind of
pedantic, however I'm trying to cover all corner cases, or else it's pointless
if it ends up causing fonts.dir creation anyways due to some oddity or another.

Thoughts?
Comment 7 Mike A. Harris 2003-10-11 05:08:07 EDT
4.3.0-39 in rawhide implements a fix for this and other issues, and should
start rather quickly now.

Note You need to log in before you can comment on or make changes to this bug.