On May 16, 2004, at 2:05 AM, Peter Gibbs (via RT) wrote:
# New Ticket Created by Peter Gibbs # Please include the string: [perl #29618] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org:80/rt3/Ticket/Display.html?id=29618 >
While investigating the test failures in the current CVS parrot, I discovered that at least one of the errors is caused by lib/Parrot/PMC.pm not being updated during Configure. This stems from the checksum algorithm used to decide if two files are the same, which will happily consider files equal as long as they contain the same bytes, regardless of position in the file.
Thus <begin> A=1 B=2 <end> and <begin> A=2 B=1 <end> are considered to match.
Here's a patch which should fix that.
JEff
Index: lib/Parrot/Configure/Step.pm
===================================================================
RCS file: /cvs/public/parrot/lib/Parrot/Configure/Step.pm,v
retrieving revision 1.23
diff -u -b -r1.23 Step.pm
--- lib/Parrot/Configure/Step.pm 24 Apr 2004 12:04:54 -0000 1.23
+++ lib/Parrot/Configure/Step.pm 16 May 2004 20:32:40 -0000
@@ -105,34 +105,13 @@
return integrate($value, $input);
}
-=item C<file_checksum($filename, $ignorePattern)>
-
-Creates a checksum for the specified file. This is used to compare files.
-
-Any lines matching the regular expression specified by C<$ignorePattern>
-are not included in the checksum.
-
-=cut
-
-sub file_checksum {
- my ($filename, $ignorePattern) = @_;
- open(FILE, "< $filename") or die "Can't open $filename: $!";
- my $sum = 0;
- while (<FILE>) {
- next if defined($ignorePattern) && /$ignorePattern/;
- $sum += unpack("%32C*", $_);
- }
- close FILE;
- return $sum;
-}
-
=item C<copy_if_diff($from, $to, $ignorePattern)>
Copies the file specified by C<$from> to the location specified by C<$to>
if it's contents have changed.
-The regular expression specified by C<$ignorePattern> is passed to
-C<file_checksum()> when comparing the files.
+Lines matching the regular expression specified by C<$ignorePattern> are
+ignored when comparing the files.
=cut
@@ -141,9 +120,21 @@
# Don't touch the file if it didn't change (avoid unnecessary rebuilds)
if (-r $to) {
- my $from_sum = file_checksum($from, $ignorePattern);
- my $to_sum = file_checksum($to, $ignorePattern);
- return if $from_sum == $to_sum;
+ open(FROM, "< $from") or die "Can't open $from: $!";
+ open(TO, "< $to") or die "Can't open $to: $!";
+
+ if (!defined $ignorePattern) { #if no pattern, compare raw contents
+ if(-s $from == -s $to) { #check lengths equal first
+ local $/;
+ return if <FROM> eq <TO>;
+ }
+ }
+ else {
+ my $fromFiltered = join "", grep !/$ignorePattern/, <FROM>;
+ my $toFiltered = join "", grep !/$ignorePattern/, <TO>;
+
+ return if $fromFiltered eq $toFiltered;
+ }
}
File::Copy::copy($from, $to);