equal
deleted
inserted
replaced
1 #! /usr/bin/perl |
|
2 use strict; |
|
3 use warnings; |
|
4 use File::Temp; |
|
5 |
|
6 my $pattern = "# sha1:"; |
|
7 |
|
8 die "need exactly one filename" if not @ARGV == 1; |
|
9 |
|
10 if ($0 =~ /chk/) { |
|
11 local $" = ""; |
|
12 exit 0 if not -e $ARGV[0]; |
|
13 my @file = <>; |
|
14 |
|
15 my $expected = ""; |
|
16 $expected = pop @file if $file[-1] =~ /^$pattern/; |
|
17 |
|
18 my $tmp = new File::Temp; |
|
19 open(SHA1, "|sha1sum >" . $tmp->filename); |
|
20 print SHA1 @file; |
|
21 close(SHA1); |
|
22 seek($tmp, 0, 0); |
|
23 |
|
24 my $current = $pattern . <$tmp>; |
|
25 |
|
26 exit 0 if $current eq $expected; |
|
27 exit 1; |
|
28 } |
|
29 |
|
30 if ($0 =~ /sig/) { |
|
31 local $" = ""; |
|
32 open(FILE, "+<$ARGV[0]") or die "Can't open $ARGV[0]: $!\n"; |
|
33 my @file = <FILE>; |
|
34 pop @file if $file[-1] =~ /^$pattern/; |
|
35 seek(FILE, 0, 0); |
|
36 print FILE @file, $pattern; |
|
37 truncate(FILE, tell FILE); |
|
38 close FILE; |
|
39 open(SHA1, "|sha1sum >>$ARGV[0]"); |
|
40 print SHA1 @file; |
|
41 close(SHA1); |
|
42 } |
|