Преглед на файлове

Dpkg::Compression::FileHandle: Add %opts to ensure_open() member

This options will be passed down the the (un)compressor spawn()'s
call.
Guillem Jover преди 12 години
родител
ревизия
379a071c36
променени са 2 файла, в които са добавени 24 реда и са изтрити 10 реда
  1. 1 0
      debian/changelog
  2. 23 10
      scripts/Dpkg/Compression/FileHandle.pm

+ 1 - 0
debian/changelog

@@ -75,6 +75,7 @@ dpkg (1.17.11) UNRELEASED; urgency=low
   * Perl modules:
   * Perl modules:
     - Add new set_as_auto() method to Dpkg::Substvars.
     - Add new set_as_auto() method to Dpkg::Substvars.
     - Add support for sig and delete_sig spawn() options in Dpkg::IPC.
     - Add support for sig and delete_sig spawn() options in Dpkg::IPC.
+    - Add %opts to ensure_open() member in Dpkg::Compression::FileHandle.
   * Mark Format and Installed-Size as automatic substvars in dpkg-genchanges
   * Mark Format and Installed-Size as automatic substvars in dpkg-genchanges
     and dpkg-gencontrol respectively.
     and dpkg-gencontrol respectively.
   * Warn on usage of deprecated Source-Version substvar.
   * Warn on usage of deprecated Source-Version substvar.

+ 23 - 10
scripts/Dpkg/Compression/FileHandle.pm

@@ -1,4 +1,5 @@
 # Copyright © 2008-2010 Raphaël Hertzog <hertzog@debian.org>
 # Copyright © 2008-2010 Raphaël Hertzog <hertzog@debian.org>
+# Copyright © 2012-2014 Guillem Jover <guillem@debian.org>
 #
 #
 # This program is free software; you can redistribute it and/or modify
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # it under the terms of the GNU General Public License as published by
@@ -18,7 +19,7 @@ package Dpkg::Compression::FileHandle;
 use strict;
 use strict;
 use warnings;
 use warnings;
 
 
-our $VERSION = '1.00';
+our $VERSION = '1.01';
 
 
 use Dpkg::Compression;
 use Dpkg::Compression;
 use Dpkg::Compression::Process;
 use Dpkg::Compression::Process;
@@ -146,24 +147,31 @@ sub new {
     return $self;
     return $self;
 }
 }
 
 
-=item $fh->ensure_open($mode)
+=item $fh->ensure_open($mode, %opts)
 
 
 Ensure the file is opened in the requested mode ("r" for read and "w" for
 Ensure the file is opened in the requested mode ("r" for read and "w" for
-write). Opens the file with the recorded filename if needed. If the file
+write). The options are passed down to the compressor's spawn() call, if one
+is used. Opens the file with the recorded filename if needed. If the file
 is already open but not in the requested mode, then it errors out.
 is already open but not in the requested mode, then it errors out.
 
 
 =cut
 =cut
 
 
 sub ensure_open {
 sub ensure_open {
-    my ($self, $mode) = @_;
+    my ($self, $mode, %opts) = @_;
     if (exists *$self->{mode}) {
     if (exists *$self->{mode}) {
 	return if *$self->{mode} eq $mode;
 	return if *$self->{mode} eq $mode;
 	croak "ensure_open requested incompatible mode: $mode";
 	croak "ensure_open requested incompatible mode: $mode";
     } else {
     } else {
+	# Sanitize options.
+	delete $opts{from_pipe};
+	delete $opts{from_file};
+	delete $opts{to_pipe};
+	delete $opts{to_file};
+
 	if ($mode eq 'w') {
 	if ($mode eq 'w') {
-	    $self->open_for_write();
+	    $self->open_for_write(%opts);
 	} elsif ($mode eq 'r') {
 	} elsif ($mode eq 'r') {
-	    $self->open_for_read();
+	    $self->open_for_read(%opts);
 	} else {
 	} else {
 	    croak "invalid mode in ensure_open: $mode";
 	    croak "invalid mode in ensure_open: $mode";
 	}
 	}
@@ -381,7 +389,7 @@ sub get_filehandle {
 ## INTERNAL METHODS
 ## INTERNAL METHODS
 
 
 sub open_for_write {
 sub open_for_write {
-    my ($self) = @_;
+    my ($self, %opts) = @_;
     my $filehandle;
     my $filehandle;
 
 
     croak 'cannot reopen an already opened compressed file'
     croak 'cannot reopen an already opened compressed file'
@@ -389,7 +397,7 @@ sub open_for_write {
 
 
     if ($self->use_compression()) {
     if ($self->use_compression()) {
 	*$self->{compressor}->compress(from_pipe => \$filehandle,
 	*$self->{compressor}->compress(from_pipe => \$filehandle,
-		to_file => $self->get_filename());
+		to_file => $self->get_filename(), %opts);
     } else {
     } else {
 	CORE::open($filehandle, '>', $self->get_filename)
 	CORE::open($filehandle, '>', $self->get_filename)
 	    or syserr(_g('cannot write %s'), $self->get_filename());
 	    or syserr(_g('cannot write %s'), $self->get_filename());
@@ -399,7 +407,7 @@ sub open_for_write {
 }
 }
 
 
 sub open_for_read {
 sub open_for_read {
-    my ($self) = @_;
+    my ($self, %opts) = @_;
     my $filehandle;
     my $filehandle;
 
 
     croak 'cannot reopen an already opened compressed file'
     croak 'cannot reopen an already opened compressed file'
@@ -407,7 +415,7 @@ sub open_for_read {
 
 
     if ($self->use_compression()) {
     if ($self->use_compression()) {
 	*$self->{compressor}->uncompress(to_pipe => \$filehandle,
 	*$self->{compressor}->uncompress(to_pipe => \$filehandle,
-		from_file => $self->get_filename());
+		from_file => $self->get_filename(), %opts);
         *$self->{allow_sigpipe} = 1;
         *$self->{allow_sigpipe} = 1;
     } else {
     } else {
 	CORE::open($filehandle, '<', $self->get_filename)
 	CORE::open($filehandle, '<', $self->get_filename)
@@ -448,6 +456,11 @@ C<*$self->{...}> to access the associated hash like in the example below:
 	*$self->{option} = $value;
 	*$self->{option} = $value;
     }
     }
 
 
+=head1 CHANGES
+
+=head2 Version 1.01
+
+New argument: $fh->ensure_open() accepts an %opts argument.
 
 
 =head1 AUTHOR
 =head1 AUTHOR