]> git.donarmstrong.com Git - debhelper.git/commitdiff
Merge branch 'wheezy'
authorJoey Hess <joey@kitenet.net>
Sun, 9 Sep 2012 18:28:51 +0000 (14:28 -0400)
committerJoey Hess <joey@kitenet.net>
Sun, 9 Sep 2012 18:29:26 +0000 (14:29 -0400)
Debian/Debhelper/Dh_Lib.pm
debian/changelog
doc/PROGRAMMING
t/dh-lib [new file with mode: 0755]

index 10ae69f7babd6e85985e27a4a9bbf247b3d79277..7b550b0ea5752820d98d1a84d49b5255c3aeeedc 100644 (file)
@@ -504,7 +504,8 @@ sub pkgfilename {
 # 1: package
 # 2: script to add to
 # 3: filename of snippet
-# 4: sed to run on the snippet. Ie, s/#PACKAGE#/$PACKAGE/
+# 4: either text: shell-quoted sed to run on the snippet. Ie, 's/#PACKAGE#/$PACKAGE/'
+#    or a sub to run on each line of the snippet. Ie sub { s/#PACKAGE#/$PACKAGE/ }
 sub autoscript {
        my $package=shift;
        my $script=shift;
@@ -533,18 +534,34 @@ sub autoscript {
           && !compat(5)) {
                # Add fragments to top so they run in reverse order when removing.
                complex_doit("echo \"# Automatically added by ".basename($0)."\"> $outfile.new");
-               complex_doit("sed \"$sed\" $infile >> $outfile.new");
+               autoscript_sed($sed, $infile, "$outfile.new");
                complex_doit("echo '# End automatically added section' >> $outfile.new");
                complex_doit("cat $outfile >> $outfile.new");
                complex_doit("mv $outfile.new $outfile");
        }
        else {
                complex_doit("echo \"# Automatically added by ".basename($0)."\">> $outfile");
-               complex_doit("sed \"$sed\" $infile >> $outfile");
+               autoscript_sed($sed, $infile, $outfile);
                complex_doit("echo '# End automatically added section' >> $outfile");
        }
 }
 
+sub autoscript_sed {
+       my $sed = shift;
+       my $infile = shift;
+       my $outfile = shift;
+       if (ref($sed) eq 'CODE') {
+               open(IN, $infile) or die "$infile: $!";
+               open(OUT, ">>$outfile") or die "$outfile: $!";
+               while (<IN>) { $sed->(); print OUT }
+               close(OUT) or die "$outfile: $!";
+               close(IN) or die "$infile: $!";
+       }
+       else {
+               complex_doit("sed \"$sed\" $infile >> $outfile");
+       }
+}
+
 # Removes a whole substvar line.
 sub delsubstvar {
        my $package=shift;
index 3b34f9c30b49d4c76cddb4a965b1e89c5582c2db..3f85493ad60cb0c16b602d44f49cda56df898583 100644 (file)
@@ -20,6 +20,17 @@ debhelper (9.20120609) UNRELEASED; urgency=low
 
  -- Joey Hess <joeyh@debian.org>  Thu, 05 Jul 2012 08:51:07 -0600
 
+debhelper (9.20120909) UNRELEASED; urgency=low
+
+  * autoscript() can now be passed a perl sub to run to s/// lines of
+    the script, which avoids problems with using sed, including potentially
+    building too long a sed command-line. This will become the recommended
+    interface in the future; for now it can be used by specific commands
+    such as dh_installxmlcatalogs that encounter the problem.
+    Closes: #665296 Thanks, Marcin Owsiany
+
+ -- Joey Hess <joeyh@debian.org>  Sun, 09 Sep 2012 14:23:10 -0400
+
 debhelper (9.20120830) unstable; urgency=low
 
   * dh_installcatalogs: Adjust catalog conffile conversion to avoid
index bcf1c13caaadfdc16d168ced6afabda9a9d9f0c1..e1440c91e46451c8c0ab10b53d054d7ebb768921 100644 (file)
@@ -191,13 +191,16 @@ isnative($package)
        is a native debian package.
        As a side effect, $dh{VERSION} is set to the version number of the
        package.
-autoscript($package, $scriptname, $snippetname, $sedcommands)
+autoscript($package, $scriptname, $snippetname, $sedcommands || $sub)
        Pass parameters:
         - binary package to be affected
         - script to add to
         - filename of snippet
-        - sed commands to run on the snippet. Ie, s/#PACKAGE#/$PACKAGE/
-          (optional) Note: Passed to the shell inside double quotes.
+        - (optional) EITHER sed commands to run on the snippet. Ie,
+          s/#PACKAGE#/$PACKAGE/ Note: Passed to the shell inside double
+           quotes.
+          OR a perl sub to invoke with $_ set to each line of the snippet in
+           turn.
        This command automatically adds shell script snippets to a debian
        maintainer script (like the postinst or prerm).
        Note that in v6 mode and up, the snippets are added in reverse
diff --git a/t/dh-lib b/t/dh-lib
new file mode 100755 (executable)
index 0000000..772b1a1
--- /dev/null
+++ b/t/dh-lib
@@ -0,0 +1,31 @@
+#!/usr/bin/perl
+package Debian::Debhelper::Dh_Lib::Test;
+use strict;
+use warnings;
+use Test::More;
+
+plan(tests => 10);
+
+use_ok('Debian::Debhelper::Dh_Lib');
+
+sub ok_autoscript_result {
+       ok(-f 'debian/testpackage.postinst.debhelper');
+       open(F, 'debian/testpackage.postinst.debhelper') or die;
+       my (@c) = <F>;
+       close(F) or die;
+       like(join('',@c), qr{update-rc\.d test-script test parms with"quote >/dev/null});
+}
+
+ok(unlink('debian/testpackage.postinst.debhelper') >= 0);
+
+ok(autoscript('testpackage', 'postinst', 'postinst-init',
+              's/#SCRIPT#/test-script/g; s/#INITPARMS#/test parms with\\"quote/g'));
+ok_autoscript_result;
+
+ok(unlink('debian/testpackage.postinst.debhelper') >= 0);
+
+ok(autoscript('testpackage', 'postinst', 'postinst-init',
+              sub { s/#SCRIPT#/test-script/g; s/#INITPARMS#/test parms with"quote/g } ));
+ok_autoscript_result;
+
+ok(unlink('debian/testpackage.postinst.debhelper') >= 0);