Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix merge error when applying a diff to existing file

  • Loading branch information...
commit 333757a060449f39e58f081fb78c62ba023146f2 1 parent 219a015
@kazuho authored
Showing with 41 additions and 1 deletion.
  1. +1 −1  blockdiff_merge
  2. +40 −0 t/blockdiff_merge.t
View
2  blockdiff_merge
@@ -28,7 +28,7 @@ my $DEBUG = $ENV{DEBUG} || undef;
my $fn = shift @ARGV
or die "Usage: $0 <file>\n";
-open my $fh, '+>>', $fn
+open my $fh, (-e $fn ? '+<' : '>'), $fn
or die "failed to open file:$fn:$!";
my $blocksize = do {
View
40 t/blockdiff_merge.t
@@ -0,0 +1,40 @@
+use strict;
+use warnings;
+
+use File::Temp qw(tempdir);
+use Test::More;
+
+my $workdir = tempdir(CLEANUP => 1);
+my $testfile = "$workdir/out.txt";
+my $BS_HDR = "\1" . ("\0"x3); # 1 byte in little endian
+
+# create "hello"
+runit(
+ join '', map {
+ chr($_) . ("\0"x7) . substr "hello", $_, 1
+ } (0..4)
+);
+is read_output(), "hello";
+
+# s/e/a/
+runit(
+ "\1" . ("\0" x 7) . 'a',
+);
+is read_output(), "hallo";
+
+done_testing;
+
+sub runit {
+ my $dump = shift;
+ open my $fh, '|-', "blib/script/blockdiff_merge $testfile"
+ or die "failed to exec blockdiff_merge:$!";
+ print $fh $BS_HDR, $dump;
+ close $fh
+ or die "blockdiff_merge returned error:$?";
+}
+
+sub read_output {
+ open my $fh, '<', $testfile
+ or die "failed to open file:$testfile:$!";
+ join '', <$fh>;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.