Package: man-db
Version: 2.6.3-1
Severity: normal
Tags: upstream patch

mandb -p (which is run by the dpkg trigger) takes a lot of time to
run.  I started looking at it (again) and noticed something peculiar
(edited a bit for clarity).

# mandb -p | grep "manual pages were added"
0 manual pages were added.
# touch /usr/share/man/man3
# mandb -p | grep "manual pages were added"
1101 manual pages were added.
# touch /usr/share/man/man3
# mandb -p | grep "manual pages were added"
1101 manual pages were added.

As I haven't done anything but update the directory's mtime, I would
have expected the subsequent mandb -p runs add no pages.  I tested
this on a few Debian installs with various uses and saw similar thing
happen with their man directories.

I looked at the code and saw that mandb stores man pages' mtimes to
its database, but there's something off with the code and it gives
false positives on differing mtimes.  I didn't come up with a fix for
that issue, but using man pages' ctimes instead I could do this:

Index: man-db-2.6.3/src/check_mandirs.c
===================================================================
--- man-db-2.6.3.orig/src/check_mandirs.c       2012-10-27 12:00:13.000000000 
+0300
+++ man-db-2.6.3/src/check_mandirs.c    2012-10-28 00:31:35.200950213 +0300
@@ -316,12 +316,14 @@
                free (lg.whatis);
 }
 
-static inline void add_dir_entries (const char *path, char *infile)
+static inline void add_dir_entries (const char *path, char *infile,
+                                   time_t last)
 {
        char *manpage;
        int len;
        struct dirent *newdir;
        DIR *dir;
+       struct stat filestat;
 
        manpage = appendstr (NULL, path, "/", infile, "/", NULL);
        len = strlen (manpage);
@@ -344,7 +346,10 @@
                if (!(*newdir->d_name == '.' && 
                      strlen (newdir->d_name) < (size_t) 3)) {
                        manpage = appendstr (manpage, newdir->d_name, NULL);
-                       test_manfile (manpage, path);
+                       if (last)
+                               lstat(manpage, &filestat);
+                       if (filestat.st_ctime >= last)
+                               test_manfile (manpage, path);
                        *(manpage + len) = '\0';
                }
                
@@ -508,7 +513,7 @@
                        if (!tty)
                                fprintf (stderr, "\n");
                }
-               add_dir_entries (path, mandir->d_name);
+               add_dir_entries (path, mandir->d_name, last);
                MYDBM_CLOSE (dbf);
                amount++;
        }


Note that test_manfile calls stat on manpage too and those calls could
be merged but I left that change out of this, for simplicity's sake.

I'm happy to say that this makes the trigger work a lot faster.  What
do you think of my approach to this?


-- System Information:
Debian Release: wheezy/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: amd64 (x86_64)

Kernel: Linux 3.2.0-4-amd64 (SMP w/6 CPU cores)
Locale: LANG=C, LC_CTYPE=fi_FI.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages man-db depends on:
ii  bsdmainutils           9.0.3
ii  debconf [debconf-2.0]  1.5.46
ii  dpkg                   1.16.9
ii  groff-base             1.21-9
ii  libc6                  2.13-36
ii  libgdbm3               1.8.3-11
ii  libpipeline1           1.2.2-1
ii  zlib1g                 1:1.2.7.dfsg-13

man-db recommends no packages.

Versions of packages man-db suggests:
ii  chromium [www-browser]   22.0.1229.94~r161065-2
ii  elinks [www-browser]     0.12~pre5-8
ii  groff                    1.21-9
ii  iceweasel [www-browser]  10.0.10esr-1
ii  konqueror [www-browser]  4:4.8.4-2
ii  less                     451-1
ii  w3m [www-browser]        0.5.3-8

-- debconf information excluded


-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to