forked from librsync/librsync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-rdiff
executable file
·44 lines (37 loc) · 1.14 KB
/
check-rdiff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/perl
# Creates a pair of semi-random files and check if rdiff
# correctlys updates the first to the second.
# script is "./g"
$size = 5 << 30;
$blocklen = 6000;
use Getopt::Long;
GetOptions("size=i" => \$size,
"blocklen=i" => \$blocklen);
$runlen = $blocklen / 3;
sub makefile { # Make a moderately random $size-byte file
($fname,$size)=@_;
print "Creating: $fname ($size bytes)\n";
open OUT,">$fname" or die "Can't open $fname";
for $i (1..$size/$runlen) {
$ch = chr(32+int(rand(127))) ;
print OUT ($ch x $runlen);
}
$ch = chr(32+int(rand(127))) ;
print OUT ($ch x ($size % $runlen));
}
sub run {
($cmd)=@_;
print "Running: $cmd\n";
system($cmd)==0 or die "FAILED!";
}
srand(0);
makefile('old',$size);
makefile('new',$size);
run("time rdiff signature -b $blocklen old old.sig");
run("time rdiff delta -s old.sig new delta");
run("time rdiff patch -s old delta new2");
print "Comparing MD5 hashes...\n";
$sum1 = `md5sum < new`; die 'Failed 1' unless $?==0; print $sum1;
$sum2 = `md5sum < new2`; die 'Failed 2' unless $?==0; print $sum2;
die "DIFFERENT\n" unless $sum1==$sum2;
print "SUCCESS\n"