Subject: | Patch for SVN-Dump-0.04 to add md5 digest support |
Date: | Fri, 23 Apr 2010 17:42:57 -0400 |
To: | bug-SVN-Dump [...] rt.cpan.org |
From: | Scott MacPhee <saldane [...] gmail.com> |
This patch adds md5 checking, and regenerates when update_headers() is called.
Additionally, accepts blank lines before head segments.
diff -r a941ac7aa981 Dump/Reader.pm
--- a/Dump/Reader.pm Fri Apr 23 15:52:40 2010 -0400
+++ b/Dump/Reader.pm Fri Apr 23 17:34:11 2010 -0400
@@ -51,6 +51,10 @@
+ ( $headers->{'Text-content-length'} || 0 )
!= ( $headers->{'Content-length'} || 0 );
+ croak "Checksum mismatch"
+ if $headers->{'Text-content-md5'}
+ && $headers->{'Text-content-md5'} ne $record->get_text_md5();
+
# if we have a delete record with a 'Node-kind' header
# we have to recurse for an included record
if ( exists $headers->{'Node-action'}
@@ -82,8 +86,11 @@
my $line = <$fh>;
croak _eof() if !defined $line;
chop $line;
- last if $line eq ''; # stop on empty line
-
+
+ # stop on empty line after we have headers
+ last if $line eq '' && keys %$headers;
+ next if $line eq '';
+
my ($key, $value) = split /: /, $line, 2;
$headers->{$key} = $value;
}
diff -r a941ac7aa981 Dump/Record.pm
--- a/Dump/Record.pm Fri Apr 23 15:52:40 2010 -0400
+++ b/Dump/Record.pm Fri Apr 23 17:34:11 2010 -0400
@@ -7,6 +7,8 @@
use SVN::Dump::Property;
use SVN::Dump::Text;
+use Digest::MD5 'md5_hex';
+
my $NL = "\012";
sub new {
@@ -89,6 +91,8 @@
if defined $self->get_text_block();
$self->set_header( 'Prop-content-length', $proplen );
$self->set_header( 'Content-length' => $proplen + $textlen );
+ $self->set_header( 'Text-content-md5' => $self->get_text_md5() )
+ if $self->get_header( 'Text-content-md5');
}
# access methods to the inner blocks
@@ -143,6 +147,13 @@
return defined $text_block ? $text_block->get() : undef;
}
+sub get_text_md5 {
+ my ($self) = @_;
+ my $text_block = $self->get_text_block();
+ my $text = defined $text_block ? $text_block->get() : '';
+ return md5_hex($text);
+}
+
1;
__END__