On Wed, Jun 20, 2012 at 10:24:52PM +0900, Norbert Preining wrote: > Good solution, agreed, and easy to implement.
I actually implemented it. See a .debdiff attached for review. Please do not upload the attached .debdiff. > and run perl foo.pl /etc/sgml/*.cat, and it told me the right files. In contrast to your implementation, my implementation ignores the complete package catalog if one file is missing. > You might have to fix add more cases to the parser, I don't know > what else is allowed in these files. Lots of things are allowed. For the non common cases, users will have to add -- update-catalog:nocheck --. So here is my RFR. Helmut
diff -Nru sgml-base-1.26+nmu3/debian/changelog sgml-base-1.26+nmu4/debian/changelog --- sgml-base-1.26+nmu3/debian/changelog 2012-05-28 21:11:52.000000000 +0200 +++ sgml-base-1.26+nmu4/debian/changelog 2012-06-21 17:00:16.000000000 +0200 @@ -1,3 +1,12 @@ +sgml-base (1.26+nmu4) experimental; urgency=low + + * Non-maintainer upload. + * update-catalog --update-super ignores catalogs referencing non-existent + files. (Closes: #676717) + * Remove warning about rebuilding packages as it may confuse users. + + -- Helmut Grohne <hel...@subdivi.de> Thu, 21 Jun 2012 16:09:07 +0200 + sgml-base (1.26+nmu3) unstable; urgency=low * Non-maintainer upload. diff -Nru sgml-base-1.26+nmu3/tools/update-catalog sgml-base-1.26+nmu4/tools/update-catalog --- sgml-base-1.26+nmu3/tools/update-catalog 2012-05-28 21:11:52.000000000 +0200 +++ sgml-base-1.26+nmu4/tools/update-catalog 2012-06-21 17:26:24.000000000 +0200 @@ -138,8 +138,6 @@ print "Invocation of dpkg-trigger failed with status $?.\n"; print "Forcing update of the super catalog...\n"; &update_super; - } else { - print "update-catalog: Please rebuild the package being set up with a version of debhelper fixing #477751.\n"; } } elsif ( $add ) @@ -240,17 +238,60 @@ } ## ---------------------------------------------------------------------- +sub check_catalog +{ + my($catalog)=shift; + my($incomment)=0; + unless(open(PKGCAT, "<", $catalog)) { + print "Warning: Ignoring unreadable catalog file `$catalog'.\n"; + return 0; + }; + while(<PKGCAT>) + { + if((not $incomment) and m/^-- update-catalog:nocheck --$/) + { + close(PKGCAT); + return 1; + } + s/--.*?--/ /g; + if(m/--/) { + if($incomment) { + s/.*?--//; + } else { + s/--.*//; + } + $incomment = 1 - $incomment; + } + if(m/CATALOG\s+(\S+)/) { + if(not -f $1) { + close(PKGCAT); + print "Warning: Ignoring catalog `$catalog' which references non-existent catalogs. See man update-catalog for details.\n"; + return 0; + } + } + } + close(PKGCAT); + if($incomment) { + print "Warning: Ignoring catalog `$catalog' with unclosed comment. See man update-catalog for details.\n"; + return 0; + } + return 1; +} +## ---------------------------------------------------------------------- sub update_super { my(@cats); my($catdir)="/etc/sgml"; my($supercat)="/var/lib/sgml-base/supercatalog"; + my($catfile); opendir(CATDIR, $catdir) or die "cannot open catalog directory $catdir: $!"; while( readdir CATDIR ) { m/^[^.].*\.cat$/ or next; - push(@cats, $catdir . "/" . $_); + $catfile = $catdir . "/" . $_; + check_catalog($catfile) or next; + push(@cats, $catfile); } closedir(CATDIR) or die "cannot close catalog directory $catdir: $!"; diff -Nru sgml-base-1.26+nmu3/tools/update-catalog.8 sgml-base-1.26+nmu4/tools/update-catalog.8 --- sgml-base-1.26+nmu3/tools/update-catalog.8 2012-05-28 13:58:23.000000000 +0200 +++ sgml-base-1.26+nmu4/tools/update-catalog.8 2012-06-21 17:17:34.000000000 +0200 @@ -45,6 +45,9 @@ extension or remove (or move) existing centralized catalogs and regenerate the super catalog using the .B --update-super option. +See section +.B SUPER CATALOG +for details on the generation process. .\" .\" ---------------------------------------------------------------------- .SH OPTIONS @@ -64,10 +67,10 @@ .B --update-super Regenerates the SGML super catalog from the contents of the .IR /etc/sgml -directory including all files having a -.B .cat -extension. -Files ending in .disabled or .old for instance are not considered. +directory. +See section +.B SUPER CATALOG +for details on the super catalog generation. .TP .B --quiet Prevents the usual diagnostic output. @@ -83,6 +86,31 @@ Display the usage information and exits. .\" .\" ---------------------------------------------------------------------- +.SH SUPER CATALOG +The super-catalog located in +.IR /etc/sgml/catalog +cannot be directly modified. +It is generated by the +.IR update-catalog +.IR --update-super +command. +The generation considers files in the +.IR /etc/sgml +directory that have a +.B .cat +extension. +For instance files ending in .old or .disabled are not considered. +Before adding a catalog to the super catalog some checks are done in order to not corrupt the super catalog. +You can disable those checks by placing a line +.B "-- update-catalog:nocheck --" +at the top of your catalog. +This might be necessary if your catalog file contains non-catalog entries. +Catalogs shipped with packages must not disable the checks. +The check verifies that all catalogs referenced from the catalog do indeed exist. +If the check fails, a message is printed and the complete catalog is ignored. +This check ensures that a catalog from a package, which is removed but not purged, is removed from the super catalog. +.\" +.\" ---------------------------------------------------------------------- .SH AUTHOR Ardo van Rangelrooij <a...@debian.org> .\"