[Debpool-commits] [SCM] Debpool Project Repository branch, master, updated. 0.2.3-63-g38a32aa

ceros-guest ceros-guest at alioth.debian.org
Tue Jun 3 07:06:56 UTC 2008


The following commit has been merged in the master branch:
commit fb4f8faadd9db4d22459b9ab9a064c9619efef88
Author: ceros-guest <ceros-guest>
Date:   Sat Dec 15 07:08:58 2007 +0000

    using bzip2 instead of Compress::Bzip2 for Bzip2 interactions

diff --git a/bin/debpool b/bin/debpool
index 2ea2032..3deab40 100755
--- a/bin/debpool
+++ b/bin/debpool
@@ -111,12 +111,8 @@ if ($Options{'compress_dists_with_zlib'}) {
     push @compression_methods, new DebPool::Gzip;
 }
 if ($Options{'bzcompress_dists'}) {
-    if (eval{ require Compress::Bzip2; }) {
-        require DebPool::Bzip2; # Bzip2 interaction routines
-        push @compression_methods, new DebPool::Bzip2;
-    } else {
-        Log_Message("libcompress-bzip2-perl is required to use bzcompress_dists.", LOG_GENERAL, LOG_WARNING);
-    }
+    require DebPool::Bzip2; # Bzip2 interaction routines
+    push @compression_methods, new DebPool::Bzip2;
 }
 
 # Before we do anything else, let's find out if we need to act as a daemon,
diff --git a/share/DebPool/Bzip2.pm b/share/DebPool/Bzip2.pm
index b256520..a00b7cc 100644
--- a/share/DebPool/Bzip2.pm
+++ b/share/DebPool/Bzip2.pm
@@ -45,6 +45,11 @@ use warnings;
 
 use POSIX; # WEXITSTATUS
 
+# Needed for open2()
+
+use Fcntl;
+use IPC::Open2;
+
 ### Module setup
 
 BEGIN {
@@ -95,55 +100,57 @@ our($Error);
 
 sub Bzip2_File {
     use DebPool::Logging qw(:functions :facility :level);
-    use Compress::Bzip2;
 
     my($file) = @_;
 
     # Open a secure tempfile to write the compressed data into
 
-    my($tmpfile) = new File::Temp( SUFFIX => '.bz2' );
-    my $bz = bzopen($tmpfile, 'wb9');
-    if (!$bz) {
-        $Error = "Couldn't initialize compression library: " . $bzerrno;
-        return undef;
-    }	
+    my($tmpfile) = new File::Temp( SUFFIX => '.bz2', UNLINK => 0 );
 
     # Open the source file so that we have it available.
+
     if (!open(SOURCE, '<', $file)) {
         $Error = "Couldn't open source file '$file': $!";
         return undef;
     }
 
-    while (1) {
-	my $buffer;
-	my $bytesread = read SOURCE, $buffer, 4096;
-	if (!defined $bytesread) {
-	    $Error = "Error reading from '$file': $!";
-	    close SOURCE;
-	    return undef;
-	}
-	last if $bytesread == 0;
-	my $byteswritten = $bz->bzwrite($buffer);
-	if ($byteswritten < $bytesread) {
-	    $Error = "Error bzwriting to temporary file: " . $bz->bzerror;
-	    close SOURCE;
-	    return undef;
-	}
-    }
+    # We are go for main engine start
+
+    my(@args) = ('--best', '--force', '--stdout');
+
+    my($bzip2_pid) = open2(*BZIP2_IN, *BZIP2_OUT, '/bin/bzip2', @args);
+
+    my($child_pid);
+    if ($child_pid = fork) { # In the parent
+        # Send all the data to Bzip2;
+
+        close(BZIP2_IN);
+        close($tmpfile);
+
+        print BZIP2_OUT <SOURCE>;
+        close(BZIP2_OUT);
+        close(SOURCE);
+
+        waitpid($child_pid, 0);
+        waitpid($bzip2_pid, 0);
+    } else { # In the child - we hope
+        if (!defined($child_pid)) {
+            die "Couldn't fork: $!\n";
+        }
+
+        # Read back the results, and print them into the tempfile.
+
+        close(BZIP2_OUT);
+        close(SOURCE);
 
-	my $bzflush = $bz->bzflush(BZ_FINISH);
+        print $tmpfile <BZIP2_IN>;
+        close(BZIP2_IN);
+        close($tmpfile);
 
-	# BZ_OK and BZ_STREAM_END are ok
-    if (($bzflush != BZ_OK) && ($bzflush != BZ_STREAM_END)) {
-	$Error = "Error flushing compressed file: " . $bz->bzerror;
-	close SOURCE;
-	return undef;
+        exit(0);
     }
 
     # And we're done
-    close SOURCE;
-    $bz->bzclose;
-    $tmpfile->unlink_on_destroy(0);
     return $tmpfile->filename;
 }
 
diff --git a/share/DebPool/Config.pm b/share/DebPool/Config.pm
index 18c0d1a..5d4a28f 100644
--- a/share/DebPool/Config.pm
+++ b/share/DebPool/Config.pm
@@ -540,8 +540,7 @@ $OptionDefs{'compress_dists_with_zlib'} = 'compress_dists_with_zlib!';
 =item B<bzcompress_dists> = I<boolean>
 
 This determines whether or not compressed versions of the distribution
-files (Packages.gz, Sources.gz) are generated in bzip2. Note that enabling
-this introduces a dependancy on libcompress-bzip2-perl.
+files (Packages.gz, Sources.gz) are generated in bzip2.
 
 =cut
 

-- 
Debpool Project Repository



More information about the Debpool-commits mailing list