[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

dpkg-source patch (Re: #39299 (bz2 format for source packages))



Following the .signature is a patch for dpkg that implements bzip2
support in dpkg-source and dpkg-buildpackage.  For example:

dpkg-buildpackage -bz2 -rfakeroot

Note that dpkg-source -x will detect bz2 archives automatically; you
just need to tell it to use bz2 when building.  Also, diffs are not
bz2'ed, since few are over 20k (and thus the extra compression is not
really needed), although they could be.

I freely admit the code sucks, so please improve as needed.


Chris
-- 
=============================================================================
|        Chris Lawrence       |  Your source for almost nothing of value:   |
|   <quango@watervalley.net>  |          http://www.lordsutch.com/          |
|                             |                                             |
|   Grad Student, Pol. Sci.   |   Visit the Lurker's Guide to Babylon 5:    |
|  University of Mississippi  |   <*> http://www.midwinter.com/lurk/ <*>    |
=============================================================================

diff --exclude=*~ -ru dpkg-1.4.1.16/debian/changelog dpkg-bz2/debian/changelog
--- dpkg-1.4.1.16/debian/changelog	Thu Oct 14 21:04:13 1999
+++ dpkg-bz2/debian/changelog	Tue Oct 19 21:13:57 1999
@@ -1,3 +1,10 @@
+dpkg (1.4.1.17) unstable; urgency=low
+
+  * Non-maintainer release.
+  * Adds bzip2 support to dpkg-source.
+
+ -- Chris Lawrence <lawrencc@debian.org>  Tue, 19 Oct 1999 21:01:46 -0500
+
 dpkg (1.4.1.16) unstable; urgency=medium
 
   * Hardcode ENOENT again since the errno-part of the POSIX module
diff --exclude=*~ -ru dpkg-1.4.1.16/scripts/dpkg-buildpackage.sh dpkg-bz2/scripts/dpkg-buildpackage.sh
--- dpkg-1.4.1.16/scripts/dpkg-buildpackage.sh	Mon Sep 27 18:19:11 1999
+++ dpkg-bz2/scripts/dpkg-buildpackage.sh	Tue Oct 19 21:06:31 1999
@@ -30,6 +30,7 @@
          -sd           uploaded src is diff and .dsc only   }
          -nc           do not clean source tree (implies -b)
          -tc           clean source tree when finished
+         -bz2          use bzip2 instead of gzip compression
          -h            print this message
 END
 }
@@ -49,6 +50,7 @@
 since=''
 maint=''
 desc=''
+bz2=''
 noclean=false
 
 while [ $# != 0 ]
@@ -72,6 +74,7 @@
 	-nc)	noclean=true; binaryonly=-b ;;
 	-b)	binaryonly=-b ;;
 	-B)	binaryonly=-B; binarytarget=binary-arch ;;
+        -bz2)   bz2=-bz2 ;;
 	-v*)	since="$value" ;;
 	-m*)	maint="$value" ;;
 	-C*)	descfile="$value" ;;
@@ -140,7 +143,7 @@
 	withecho $rootcommand debian/rules clean $archlist
 fi
 if [ x$binaryonly = x ]; then
-	cd ..; withecho dpkg-source -b "$dirn"; cd "$dirn"
+	cd ..; withecho dpkg-source $bz2 -b "$dirn"; cd "$dirn"
 fi
 withecho debian/rules build $archlist
 withecho $rootcommand debian/rules $binarytarget $archlist
diff --exclude=*~ -ru dpkg-1.4.1.16/scripts/dpkg-source.1 dpkg-bz2/scripts/dpkg-source.1
--- dpkg-1.4.1.16/scripts/dpkg-source.1	Sun Sep 26 20:17:04 1999
+++ dpkg-bz2/scripts/dpkg-source.1	Tue Oct 19 21:15:23 1999
@@ -265,6 +265,16 @@
 or the empty string (no original source, and so no diff) depending on
 the arguments.
 .TP
+.B -bz2
+Create a source tar file compressed using bzip2 format, rather than gzip.
+Source packages built this way are only compatible with dpkg-dev
+versions 1.4.1.17 and above.  (This option will be passed through from
+dpkg-buildpackage if specified on its command line.)  Note that the
+.B diff
+file will still be compressed with
+.B gzip
+and have a .gz extension.
+.TP
 .BR -sa , -sp , -su , -sk , -sA , -sP , -sU , -sK , -ss " with " -b
 If
 .BR -sk " or " -sp
diff --exclude=*~ -ru dpkg-1.4.1.16/scripts/dpkg-source.pl dpkg-bz2/scripts/dpkg-source.pl
--- dpkg-1.4.1.16/scripts/dpkg-source.pl	Tue Sep 28 22:36:29 1999
+++ dpkg-bz2/scripts/dpkg-source.pl	Tue Oct 19 21:09:54 1999
@@ -9,6 +9,7 @@
 my $fn;
 
 $sourcestyle = 'X';
+$bz2mode = 0;
 
 use POSIX;
 use POSIX qw (:errno_h :signal_h);
@@ -34,6 +35,7 @@
                  -T<varlistfile>     read variables here, not debian/substvars
                  -D<field>=<value>   override or add a .dsc field and value
                  -U<field>           remove a field
+                 -bz2                use bzip2 instead of gzip compression
                  -sa                 auto select orig source (-sA is default)
                  -sk                 use packed orig source (unpack & keep)
                  -sp                 use packed orig source (unpack & remove)
@@ -77,6 +79,8 @@
         $varlistfile= $';
     } elsif (m/^-h$/) {
         &usageversion; exit(0);
+    } elsif (m/^-bz2/) {
+        $bz2mode = 1;
     } elsif (m/^--$/) {
         last;
     } else {
@@ -192,7 +196,11 @@
 #print STDERR ">$basedirname<\n";
 
     $origdir= "$dir.orig";
-    $origtargz= "$basename.orig.tar.gz";
+    if ($bz2mode) {
+        $origtargz= "$basename.orig.tar.bz2";
+    } else {
+        $origtargz= "$basename.orig.tar.gz";
+    }
     if (@ARGV) {
         $origarg= shift(@ARGV);
         if (length($origarg)) {
@@ -203,7 +211,7 @@
                 $sourcestyle =~ y/aA/rR/;
                 $sourcestyle =~ m/[ursURS]/ ||
                     &error("orig argument is unpacked but source handling style".
-                           " -s$sourcestyle calls for packed (.orig.tar.gz)");
+                           " -s$sourcestyle calls for packed (.orig.tar.gz/bz2)");
             } elsif (-f _) {
                 $origtargz= $origarg;
                 $sourcestyle =~ y/aA/pP/;
@@ -250,12 +258,22 @@
         $tardirbase= $origdirbase; $tardirname= $origdirname;
 
         $tarname= $origtargz;
-        $tarname eq "$basename.orig.tar.gz" ||
-            &warn(".orig.tar.gz name $tarname is not <package>_<upstreamversion>".
-                  ".orig.tar.gz (wanted $basename.orig.tar.gz)");
+        if ($bz2mode) {
+            $tarname eq "$basename.orig.tar.bz2" ||
+                &warn(".orig.tar.bz2 name $tarname is not <package>_<upstreamversion>".
+                      ".orig.tar.bz2 (wanted $basename.orig.tar.bz2)");
+        } else {
+            $tarname eq "$basename.orig.tar.gz" ||
+                &warn(".orig.tar.gz name $tarname is not <package>_<upstreamversion>".
+                      ".orig.tar.gz (wanted $basename.orig.tar.gz)");
+        }
     } else {
         $tardirbase= $dirbase; $tardirname= $dirname;
-        $tarname= "$basenamerev.tar.gz";
+        if ($bz2mode) {
+            $tarname= "$basenamerev.tar.bz2";
+        } else {
+            $tarname= "$basenamerev.tar.gz";
+        }
     }
 
 #print STDERR ">$dir|$origdir|$origtargz|$sourcestyle<\n";
@@ -327,7 +345,7 @@
         
         print("$progname: building $sourcepackage in $basenamerev.diff.gz\n")
             || &syserr("write building diff message");
-        &forkgzipwrite("$basenamerev.diff.gz");
+        &forkgzipwrite("$basenamerev.diff.gz", 0);
 
         defined($c2= open(FIND,"-|")) || &syserr("fork for find");
         if (!$c2) {
@@ -451,7 +469,7 @@
     exit(0);
 
 } else {
-
+    $bz2mode = 0;
     $sourcestyle =~ y/X/p/;
     $sourcestyle =~ m/[pun]/ ||
         &usageerr("source handling style -s$sourcestyle not allowed with -x");
@@ -494,6 +512,7 @@
             || &error("Files field contains bad line \`$file'");
         ($md5sum{$3},$size{$3},$file) = ($1,$2,$3);
         &setfile(\$tarfile) if $file =~ m/\.tar\.gz$/;
+        &setfile(\$tarfile) if $file =~ m/\.tar\.bz2$/;
         &setfile(\$difffile) if $file =~ m/\.diff\.gz$/;
     }
 
@@ -501,6 +520,8 @@
     $expectprefix= $newdirectory; $expectprefix.= '.orig' if length($difffile);
     
     length($tarfile) || &error("no tarfile in Files field");
+    $bz2mode=1 if $tarfile =~ m/\.bz2$/;
+
     checkstats($tarfile);
     checkstats($difffile) if length($difffile);
 
@@ -508,7 +529,7 @@
 
     if (length($difffile)) {
             
-        &forkgzipread("$dscdir/$difffile");
+        &forkgzipread("$dscdir/$difffile", 0);
         $/="\n";
 	$_ = <GZIP>;
         while ($_ || !eof(GZIP)) {
@@ -624,7 +645,7 @@
             }
         }                
 
-        &forkgzipread("$dscdir/$difffile");
+        &forkgzipread("$dscdir/$difffile", 0);
         defined($c2= fork) || &syserr("fork for patch");
         if (!$c2) {
             open(STDIN,"<&GZIP") || &syserr("reopen gzip for patch");
@@ -966,8 +987,35 @@
     $ur++;
 }
 
+sub forkbzip2write {
+    open(GZIPFILE,"> $_[0]") || &syserr("create file $_[0]");
+    pipe(BZIP2READ,GZIP) || &syserr("pipe for bzip2");
+    defined($cgz= fork) || &syserr("fork for bzip2");
+    if (!$cgz) {
+        open(STDIN,"<&BZIP2READ") || &syserr("reopen bzip2 pipe"); close(BZIP2READ);
+        close(GZIP); open(STDOUT,">&GZIPFILE") || &syserr("reopen tar.gz");
+        exec('bzip2','-9c'); &syserr("exec bzip2");
+    }
+    close(BZIP2READ);
+    $gzipsigpipeok= 0;
+}
+
+sub forkbzip2read {
+    open(GZIPFILE,"< $_[0]") || &syserr("read file $_[0]");
+    pipe(GZIP,BZIP2WRITE) || &syserr("pipe for bunzip2");
+    defined($cgz= fork) || &syserr("fork for bunzip2");
+    if (!$cgz) {
+        open(STDOUT,">&BZIP2WRITE") || &syserr("reopen bunzip2 pipe"); close(BZIP2WRITE);
+        close(GZIP); open(STDIN,"<&GZIPFILE") || &syserr("reopen input file");
+        exec('bunzip2','-c'); &syserr("exec bunzip2");
+    }
+    close(BZIP2WRITE);
+    $gzipsigpipeok= 1;
+}
+
 sub forkgzipwrite {
 #print STDERR "forkgzipwrite $_[0]\n";
+    return forkbzip2write($_[0]) if( $bz2mode && length(@_) == 1 );
     open(GZIPFILE,"> $_[0]") || &syserr("create file $_[0]");
     pipe(GZIPREAD,GZIP) || &syserr("pipe for gzip");
     defined($cgz= fork) || &syserr("fork for gzip");
@@ -982,6 +1030,7 @@
 
 sub forkgzipread {
 #print STDERR "forkgzipread $_[0]\n";
+    return forkbzip2read($_[0]) if( $bz2mode && length(@_) == 1 );
     open(GZIPFILE,"< $_[0]") || &syserr("read file $_[0]");
     pipe(GZIP,GZIPWRITE) || &syserr("pipe for gunzip");
     defined($cgz= fork) || &syserr("fork for gunzip");


Reply to: