tag 430118 patch thanks Hi,
I'm attaching a proposed patch that fixes these RC issues mentioned in this bug report. 1) update-perl-sax-parsers makes the default parser be the last one returned by readdir(), resulting in the worst possible choice (XML::SAX::PurePerl) on ext3 filesystems with the dir_index option. The proposed fix is to assign a priority to each parser and set the XML::SAX::PurePerl priority low enough that all others will override it. The priorities are encoded into the ParserDetails.d entry filenames. The default priority is 50, XML::SAX::PurePerl gets 10, and parsers with the same priority are sorted in an alphabetic order. The priorities should be discussed between the maintainers of the parser modules (at least libxml-libxml-perl and libxml-sax-expat-perl). Currently XML::SAX::Expat ends up last and thus is the default parser when installed. This is probably the desired end result as well, so the transition should be smooth. 2) local changes to /etc/perl/XML/SAX/ParserDetails.ini aren't honored The patch handles the configuration file with ucf. The preinst script calculates and stores the md5sum for an unmodified config file to make sure that ucf dialogs don't pop up without reason. 3) local changes to the parser entries in /etc/perl/XML/SAX/ParserDetails.d/ aren't honored The patch moves the ParserDetails.d directory under /var/lib/libxml-sax-perl. This means that the priorities introduced in 1) can't be overridden by local configuration. I considered this but decided that it would be overengineering, as local configuration can go into the resulting ParserDetails.ini as well. The issues should possibly cloned into three separate bugs, but the patches can't really be made independent since they touch the same parts of the code in several places. The patch is formatted as an NMU, but the changes inside aren't quite as minimal as would perhaps be proper for that. In particular, I decided to remove the preinst pre-sarge cleanup of different iterations of the /etc/perl/XML/SAX directory rather than patch the logic to handle yet one move. As the changes are rather extensive, I'd prefer something like this to be included in a maintainer upload rather than an NMU. Jay, I haven't seen anything from you on this since July. Would it be OK with you if we adopted this for the pkg-perl group? Any comments on the patch are naturally welcome. Cheers, -- Niko Tyni [EMAIL PROTECTED]
diff -u libxml-sax-perl-0.16/SAX.pm libxml-sax-perl-0.16/SAX.pm --- libxml-sax-perl-0.16/SAX.pm +++ libxml-sax-perl-0.16/SAX.pm @@ -219,14 +219,16 @@ sub save_parsers_debian { my $class = shift; - my ($parser_module,$directory) = @_; + my ($parser_module,$directory, $priority) = @_; # add parser $known_parsers = []; $class->add_parser($parser_module); # get parser's ParserDetails file - my $file = File::Spec->catfile($directory, $parser_module); + my $file = $parser_module; + $file = "${priority}-$file" if $priority != 0; + $file = File::Spec->catfile($directory, $file); chmod 0644, $file; unlink($file); diff -u libxml-sax-perl-0.16/debian/changelog libxml-sax-perl-0.16/debian/changelog --- libxml-sax-perl-0.16/debian/changelog +++ libxml-sax-perl-0.16/debian/changelog @@ -1,3 +1,17 @@ +libxml-sax-perl (0.16-0.2) unstable; urgency=low + + * NMU. + * Add support for SAX parser priorities. + + lower the XML::SAX::PurePerl priority so that it will not be the + default parser anymore if any others are available. (Closes: #430118) + * Move the /etc/perl/XML/SAX/ParserDetails.d directory under + /var/lib/libxml-sax-perl, since it's not really configuration data. + * Use ucf to manage local changes to /etc/perl/XML/SAX/ParserDetails.ini. + * Remove the pre-sarge preinst cleanup of /etc/XML and /etc/perl/SAX + introduced in 0.12-3. + + -- Niko Tyni <[EMAIL PROTECTED]> Thu, 08 Nov 2007 21:54:35 +0200 + libxml-sax-perl (0.16-0.1) unstable; urgency=low * Non-maintainer upload. diff -u libxml-sax-perl-0.16/debian/control libxml-sax-perl-0.16/debian/control --- libxml-sax-perl-0.16/debian/control +++ libxml-sax-perl-0.16/debian/control @@ -10,7 +10,7 @@ Section: perl Priority: optional Architecture: all -Depends: ${perl:Depends}, libxml-namespacesupport-perl +Depends: ${perl:Depends}, libxml-namespacesupport-perl, ucf (>= 0.28) Description: Perl module for using and building Perl SAX2 XML processors This module consists of several framework classes for using and building Perl SAX2 XML parsers, filters, and drivers. It is designed diff -u libxml-sax-perl-0.16/debian/libxml-sax-perl.README.Debian libxml-sax-perl-0.16/debian/libxml-sax-perl.README.Debian --- libxml-sax-perl-0.16/debian/libxml-sax-perl.README.Debian +++ libxml-sax-perl-0.16/debian/libxml-sax-perl.README.Debian @@ -41,13 +41,18 @@ 2. Generate the file 'ParserDetails.ini' by concatenating the contents of the remaining files in the 'ParserDetails.d' directory. -This script uses the directory '/etc/perl/XML/SAX/ParserDetails.d' and +This script uses the directory '/var/lib/libxml-sax-perl/ParserDetails.d' and the file '/etc/perl/XML/SAX/ParserDetails.ini' by default. To keep the default behaviour of the XML::SAX module the file '/usr/share/perl5/XML/SAX/ParserDetails.ini' is symlinked to the file '/etc/perl/XML/SAX/ParserDetails.ini'. +The file '/etc/perl/XML/SAX/ParserDetails.ini' is managed with ucf(1) +to ensure that local changes are not accidentally overwritten. If +you choose to keep a locally modified file but change your mind later, +you can get update-perl-sax-parsers to overwrite your modified file +by running 'ucf --purge '/etc/perl/XML/SAX/ParserDetails.ini' first. Support for Debian packages with Perl SAX parser modules -------------------------------------------------------- @@ -57,6 +62,20 @@ script. This is done by putting the appropriate invocations of this script in the postinst and the prerm scripts of that package. +Starting with libxml-sax-perl version 0.16-0.2, the +'update-perl-sax-parsers' script supports parser-specific priorities. +The idea is that the parser with the highest priority gets to be the +default SAX parser. The bundled parser, XML::SAX::PurePerl, is not +recommended for serious use, so its priority is set to 10. The default +priority, when the '--priority' option is not used, is 50. + +Parsers with the same priority are ordered alphabetically by their module +name, and the last one is the winner. + +If you want to change the priority of your module later, just remove +the module with the old priority and the re-add it with the new +priority. + Below is an example of a postinst script: #!/bin/sh @@ -70,7 +89,12 @@ ## ---------------------------------------------------------------------- if [ "$1" = configure ] then - update-perl-sax-parsers --add XML::FOO + if [ -n "$2" ] && dpkg --compare-versions "$2" lt x.x-x + then + update-perl-sax-parsers --remove XML::FOO + fi + + update-perl-sax-parsers --add XML::FOO --priority 60 update-perl-sax-parsers --update fi @@ -95,7 +119,7 @@ ## ---------------------------------------------------------------------- if [ "$1" = remove ] then - update-perl-sax-parsers --remove XML::FOO + update-perl-sax-parsers --remove XML::FOO --priority 60 update-perl-sax-parsers --update fi @@ -107,10 +131,9 @@ ## ---------------------------------------------------------------------- -For the above to work properly the package needs to have a dependencty -on the package 'libxml-sax-perl'. You can find these examples in the -directory '/usr/share/doc/libxml-sax-perl/examples'. - +For the above to work properly the package needs to have a versioned +dependency on 'libxml-sax-perl (>= 0.16-0.2)'. You can find these +examples in the directory '/usr/share/doc/libxml-sax-perl/examples'. Local Parser SAX parser module registration ------------------------------------------- @@ -119,7 +142,7 @@ local Perl SAX parser module registration. When (de)registering a Perl SAX parser module to the registry one can -indicate a directory (default is '/etc/perl/XML/SAX/ParserDetails.d'), +indicate a directory (default is '/var/lib/libxml-sax-perl/ParserDetails.d'), e.g.: update-perl-sax-parsers --add XML::FOO \ @@ -139,7 +162,7 @@ update-perl-sax-parsers --update \ --file /usr/local/share/perl5/XML/SAX/ParserDetails.ini \ --directory /usr/local/share/perl5/XML/SAX/ParserDetails.d \ - --directory /etc/perl/XML/SAX/ParserDetails.d + --directory /var/lib/libxml-sax-perl/ParserDetails.d Original CPAN Package vs. Debian Package @@ -155,2 +178,3 @@ --- -Ardo van Rangelrooij <[EMAIL PROTECTED]> +This text was originally written by Ardo van Rangelrooij <[EMAIL PROTECTED]>. + +-- Niko Tyni <[EMAIL PROTECTED]> Thu, 08 Nov 2007 00:54:30 +0200 diff -u libxml-sax-perl-0.16/debian/libxml-sax-perl.postinst libxml-sax-perl-0.16/debian/libxml-sax-perl.postinst --- libxml-sax-perl-0.16/debian/libxml-sax-perl.postinst +++ libxml-sax-perl-0.16/debian/libxml-sax-perl.postinst @@ -9,7 +9,29 @@ ## ---------------------------------------------------------------------- if [ "$1" = configure ] then - update-perl-sax-parsers --quiet --add XML::SAX::PurePerl + if which ucfr >/dev/null 2>&1 + then + ucfr libxml-sax-perl /etc/perl/XML/SAX/ParserDetails.ini + fi + + if [ -n "$2" ] && dpkg --compare-versions "$2" le 0.16-0.1 + then + # first, move /etc/perl/XML/SAX/ParserDetails.d/ under + # /var/lib/libxml-sax-perl + for i in /etc/perl/XML/SAX/ParserDetails.d/* + do + # the directory should never be empty, but the [ ! -e ] + # construct handles an unexpanded glob just in case + [ ! -e "$i" ] || \ + mv "$i" "/var/lib/libxml-sax-perl/ParserDetails.d/50-$(basename $i)" + done + rmdir --ignore-fail-on-non-empty /etc/perl/XML/SAX/ParserDetails.d + + # now downgrade XML::SAX::PurePerl priority by removing it first + update-perl-sax-parsers --quiet --remove XML::SAX::PurePerl + fi + + update-perl-sax-parsers --quiet --add XML::SAX::PurePerl --priority 10 update-perl-sax-parsers --quiet --update fi diff -u libxml-sax-perl-0.16/debian/libxml-sax-perl.postrm libxml-sax-perl-0.16/debian/libxml-sax-perl.postrm --- libxml-sax-perl-0.16/debian/libxml-sax-perl.postrm +++ libxml-sax-perl-0.16/debian/libxml-sax-perl.postrm @@ -10,8 +10,15 @@ if [ "$1" = purge ] then rm -f /etc/perl/XML/SAX/ParserDetails.ini - cd /etc/perl && \ - rmdir --parents --ignore-fail-on-non-empty XML/SAX/ParserDetails.d + rm -r /var/lib/libxml-sax-perl + if which ucf >/dev/null 2>&1 + then + ucf --purge /etc/perl/XML/SAX/ParserDetails.ini + fi + if which ucfr >/dev/null 2>&1 + then + ucfr --purge libxml-sax-perl /etc/perl/XML/SAX/ParserDetails.ini + fi fi ## ---------------------------------------------------------------------- diff -u libxml-sax-perl-0.16/debian/libxml-sax-perl.preinst libxml-sax-perl-0.16/debian/libxml-sax-perl.preinst --- libxml-sax-perl-0.16/debian/libxml-sax-perl.preinst +++ libxml-sax-perl-0.16/debian/libxml-sax-perl.preinst @@ -6,64 +6,13 @@ ## ---------------------------------------------------------------------- set -e -## ---------------------------------------------------------------------- -if [ "$1" = "install" -o "$1" = "upgrade" ] +if [ "$1" = "upgrade" ] && dpkg --compare-versions "$2" le 0.16.0.1 then + # find out the md5sum of an unmodified ParserDetails.ini - ## ------------------------------------------------------------------ - if [ ! -d /etc/perl/XML/SAX ] - then - cd /etc - mkdir --parents perl/XML/SAX/ParserDetails.d - touch perl/XML/SAX/ParserDetails.ini - fi - - ## ------------------------------------------------------------------ - if [ -d /etc/XML/SAX/ParserDetails.d ] - then - cd /etc/XML/SAX/ParserDetails.d - if [ -n "`\ls`" ] - then - for f in `\ls` - do - if [ ! -f /etc/perl/XML/SAX/ParserDetails.d/${f} ] - then - mv -f ${f} /etc/perl/XML/SAX/ParserDetails.d/. - else - rm -f ${f} - fi - done - fi - cd /etc/XML/SAX - rm -f ParserDetails.ini - cd /etc - rmdir --parents --ignore-fail-on-non-empty XML/SAX/ParserDetails.d - - fi - - ## ------------------------------------------------------------------ - if [ -d /etc/perl/SAX/ParserDetails.d ] - then - cd /etc/perl/SAX/ParserDetails.d - if [ -n "`\ls`" ] - then - for f in `\ls` - do - if [ ! -f /etc/perl/XML/SAX/ParserDetails.d/${f} ] - then - mv -f ${f} /etc/perl/XML/SAX/ParserDetails.d/. - else - rm -f ${f} - fi - done - fi - cd /etc/perl/SAX - rm -f ParserDetails.ini - cd /etc/perl - rmdir --parents --ignore-fail-on-non-empty SAX/ParserDetails.d - - fi - + [ -d /var/lib/libxml-sax-perl ] || mkdir --parents /var/lib/libxml-sax-perl + update-perl-sax-parsers --quiet --update --file - | md5sum - \ + > /var/lib/libxml-sax-perl/ParserDetails.ini.md5sum fi ## ---------------------------------------------------------------------- diff -u libxml-sax-perl-0.16/examples/libxml-foo-perl.postinst libxml-sax-perl-0.16/examples/libxml-foo-perl.postinst --- libxml-sax-perl-0.16/examples/libxml-foo-perl.postinst +++ libxml-sax-perl-0.16/examples/libxml-foo-perl.postinst @@ -9,7 +9,12 @@ ## ---------------------------------------------------------------------- if [ "$1" = configure ] then - update-perl-sax-parsers --add XML::FOO + if [ -n "$2" ] && dpkg --compare-versions "$2" lt x.x-x + then + update-perl-sax-parsers --remove XML::FOO + fi + + update-perl-sax-parsers --add XML::FOO --priority 60 update-perl-sax-parsers --update fi diff -u libxml-sax-perl-0.16/update-perl-sax-parsers libxml-sax-perl-0.16/update-perl-sax-parsers --- libxml-sax-perl-0.16/update-perl-sax-parsers +++ libxml-sax-perl-0.16/update-perl-sax-parsers @@ -1,8 +1,9 @@ #!/usr/bin/perl ## ---------------------------------------------------------------------- -## Debian update-perl-sax-parsers version 0.2 +## Debian update-perl-sax-parsers version 0.3 ## ---------------------------------------------------------------------- ## Copyright (C) 2001-2003 Ardo van Rangelrooij +## Copyright (C) 2007 Niko Tyni ## ## This is free software; see the GNU General Public Licence version 2 ## or later for copying conditions. There is NO warranty. @@ -15,6 +16,7 @@ use File::Spec; use Getopt::Long; use XML::SAX; +use File::Temp qw(tempfile); ## ---------------------------------------------------------------------- $0 =~ m|[^/]+$|; @@ -32,6 +34,8 @@ my $test = ''; my $update = ''; my $version = ''; +my $ucf; +my $priority; ## ---------------------------------------------------------------------- if ( ! GetOptions( @@ -44,6 +48,8 @@ 'test' => \$test, 'update' => \$update, 'version' => \$version, + 'priority=i' => \$priority, + 'ucf=i' => \$ucf, ) ) { @@ -71,10 +77,19 @@ if $test && ! $quiet; ## ---------------------------------------------------------------------- -my $PARSER_DETAILS_DIR = "/etc/perl/XML/SAX/ParserDetails.d"; +# default priority is 50 unless --directory was specified +# with --directory, default to 0 (no priority in the filenames) +$priority = (@directory ? 0 : 50) if not defined $priority; + +## ---------------------------------------------------------------------- +my $PARSER_DETAILS_DIR = "/var/lib/libxml-sax-perl/ParserDetails.d"; push( @directory, $PARSER_DETAILS_DIR) if ! @directory; ## ---------------------------------------------------------------------- +# use ucf by default if --file is not specified +$ucf = ($file ? 0 : 1) if not defined $ucf; + +## ---------------------------------------------------------------------- my $PARSER_DETAILS_FILE = "/etc/perl/XML/SAX/ParserDetails.ini"; $file = $PARSER_DETAILS_FILE if ! $file; @@ -84,14 +99,16 @@ print "$name: Adding Perl SAX parser module info file of $add...\n" unless $quiet; - XML::SAX->save_parsers_debian( $add, $directory[0] ); + XML::SAX->save_parsers_debian( $add, $directory[0], $priority ); } elsif ( $remove ) { print "$name: Removing Perl SAX parser module info file of $remove...\n" unless $quiet; - my $parser_file = File::Spec->catfile( $directory[0], $remove); + my $parser_file = $remove; + $parser_file = "${priority}-$parser_file" if $priority != 0; + $parser_file = File::Spec->catfile( $directory[0], $parser_file ); unlink( $parser_file ); } elsif ( $update ) @@ -99,23 +116,37 @@ print "$name: Updating overall Perl SAX parser modules info file...\n" unless $quiet; - open( PARSER_DETAILS_FILE, ">$file" ) - || die "Cannot write to $file: $!"; + my ($handle, $tmpfile); + + if ($ucf) { + ($handle, $tmpfile) = tempfile(); + chmod 0644, $tmpfile or die("chmod $tmpfile: $!"); + } else { + open( $handle, ">$file" ) + || die "Cannot write to $file: $!"; + } foreach my $directory ( @directory) { opendir( PARSER_DETAILS_DIR, $directory ) || die "Cannot access $directory: $!"; - while ( defined( my $parser_details = readdir( PARSER_DETAILS_DIR ) ) ) + my @files = sort readdir ( PARSER_DETAILS_DIR ); + for my $parser_details ( @files ) { next if $parser_details =~ /^\.\.?$/; # skip . and .. open( PARSER_DETAILS, "$directory/$parser_details" ) || die "Cannot read from $parser_details: $!"; - while ( <PARSER_DETAILS> ) { print PARSER_DETAILS_FILE; } + while ( <PARSER_DETAILS> ) { print $handle $_; } close( PARSER_DETAILS ); } closedir( PARSER_DETAILS_DIR ); } - close( PARSER_DETAILS_FILE ); + close( $handle ); + if ($ucf) { + print "$name: Running ucf on $file...\n" + unless $quiet; + system("ucf --debconf-ok --sum-file /var/lib/libxml-sax-perl/ParserDetails.ini.md5sum $tmpfile $file"); + unlink $tmpfile or die("unlink $tmpfile: $!"); + } } ## ---------------------------------------------------------------------- @@ -133,9 +164,13 @@ Options: --directory Perl SAX parser module info file directory to be used as target for 'add'/'remove' or as sources for 'update' - (default = '/etc/perl/XML/SAX/ParserDetails.d') + (default = '/var/lib/libxml-sax-perl/ParserDetails.d') + --priority The priority of the parser to add. The parser with the + highest priority is the default parser. --file Perl SAX parser module info file to be updated (default = '/etc/perl/XML/SAX/ParserDetails.ini') + --ucf X Forcibly disable (X == 0) or enable (X != 0) the use + of ucf with '--update'. --help display this help text (usage) --quiet be quiet --test do not modify any files, enable debugging mode @@ -146,7 +181,7 @@ ## ---------------------------------------------------------------------- sub version { - print "Debian $name version 0.2\n"; + print "Debian $name version 0.3\n"; } ## ---------------------------------------------------------------------- diff -u libxml-sax-perl-0.16/update-perl-sax-parsers.8 libxml-sax-perl-0.16/update-perl-sax-parsers.8 --- libxml-sax-perl-0.16/update-perl-sax-parsers.8 +++ libxml-sax-perl-0.16/update-perl-sax-parsers.8 @@ -7,7 +7,7 @@ .\" ---------------------------------------------------------------------- .\" .\" ---------------------------------------------------------------------- -.TH UPDATE-PERL-SAX-PARSERS 8 "Sep 2003" "0.2" "Debian" +.TH UPDATE-PERL-SAX-PARSERS 8 "Nov 2007" "0.3" "Debian" .\" .\" ---------------------------------------------------------------------- .SH NAME @@ -34,7 +34,7 @@ .B update-perl-sax-parsers inserts, updates and removes individual Perl SAX parser module info files in the directory -.I /etc/perl/XML/SAX/ParserDetails.d +.I /var/lib/libxml-sax-perl/ParserDetails.d and the overall Perl SAX parser modules info file .IR /etc/perl/XML/SAX/ParserDetails.ini . .\" @@ -44,16 +44,26 @@ .B --add Adds the per-module info file for the indicated Perl SAX parser module to the directory -.IR /etc/perl/XML/SAX/ParserDetails.d . +.IR /var/lib/libxml-sax-perl/ParserDetails.d . .TP .B --remove Removes the per-module info file for Perl SAX parser module from the directory -.IR /etc/perl/XML/SAX/ParserDetails.d . +.IR /var/lib/libxml-sax-perl/ParserDetails.d . .TP .B --update updates the overall Perl SAX parser modules info file .IR /etc/perl/XML/SAX/ParserDetails.ini . +The modules will be listed in an order of ascending priority. See +the PARSER PRIORITIES section below. + +The file will be managed with +.B ucf(1) , +unless the +.B --file +option is used. See also the +.B --ucf +option below. .TP .B --directory When used with @@ -66,12 +76,38 @@ .B --update indicates the ParserDetails.d directories to be used as source for generating the ParserDetails.ini file. Default is -.IR /etc/perl/XML/SAX/ParserDetails.d . +.IR /var/lib/libxml-sax-perl/ParserDetails.d . .TP .B --file Indicates the ParserDetails.ini file up be updated. Default is .IR /etc/perl/XML/SAX/ParserDetails.ini . .TP +.B --priority XX +Specifies the priority of the SAX parser module to be added +removed. The priority will be encoded +to the filename of the ParserDetails.d entry. See the PARSER PRIORITIES +section below. + +This option was added in version 0.3 of +.B update-perl-sax-parsers . +Use the value "0" to disable the encoding and match the behaviour +of earlier versions of the script. + +The default priority value is 50, unless +.B --directory +was specified, in which case the default is 0 (disabled.) +.TP +.B --ucf X +Forcibly enable (X != 0) or disable (X = 0) of +.B ucf(1) . +By default, +.B ucf(1) +will be used to manage the ParserDetails.ini file when +.B --file +is +.IR not +specified. +.TP .B --quiet Prevents any diagnostic output. .TP @@ -85,8 +121,30 @@ Display the usage information and exits. .\" .\" ---------------------------------------------------------------------- +.SH PARSER PRIORITIES +Starting with version 0.3 of +.B update-perl-sax-parsers , +the parsers are assigned a priority value that is encoded into the names +of the files in the ParserDetails.d directory. Specifically, the file +name will be "XX-Some::Module", where XX denotes the priority and Some::Module +is the name of the parser module. + +When +.B --update +is called, the parsers are listed in an order of ascending priority +into the +.IR ParserDetails.ini +file. The last parser in the file, ie. the one with the highest priority, +is the +.B default +XML::SAX parser. + +Parsers with the same priority are sorted alphabetically by their name. +This is contrary to the behaviour of earlier versions, where the +sort order was undefined and depended on underlying the file system. +.\" +.\" ---------------------------------------------------------------------- .SH NOTE -.TP Installing the original package from CPAN into /usr/local breaks the Debian package, since the former is in Perl's @INC before the latter. So, please don't do this. @@ -100,12 +158,14 @@ /usr/share/doc/libxml-sax-perl/README.Debian .\" .\" ---------------------------------------------------------------------- -.SH AUTHOR +.SH AUTHORS Ardo van Rangelrooij <[EMAIL PROTECTED]> .\" .\" ---------------------------------------------------------------------- .SH COPYRIGHT Copyright \(co 2001-2003 Ardo van Rangelrooij + +Copyright \(co 2007 Niko Tyni .PP This is free software; see the GNU General Public Licence version 2 or later for copying conditions. There is only in patch2: unchanged: --- libxml-sax-perl-0.16.orig/debian/dirs +++ libxml-sax-perl-0.16/debian/dirs @@ -0,0 +1,2 @@ +/var/lib/libxml-sax-perl/ParserDetails.d +/etc/perl/XML/SAX