Added lots more modules from lintian. Maemian appears to work.
[maemian] / checks / md5sums
1 # md5sums -- lintian check script -*- perl -*-
2
3 # Copyright (C) 1998 Christian Schwarz and Richard Braakman
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, you can find it on the World Wide
17 # Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
18 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19 # MA 02110-1301, USA.
20
21 package Maemian::md5sums;
22 use strict;
23 use Tags;
24 use Util;
25
26 sub run {
27
28 my $pkg = shift;
29 my $type = shift;
30
31 my $control = "control/md5sums";
32
33 my %control_entry;
34 my %info_entry;
35 my %conffile;
36
37 # read in md5sums info file
38 open(C, '<', "md5sums") or fail("cannot open md5sums info file: $!");
39 while (<C>) {
40     chop;
41     next if m/^\s*$/;
42     m/^(\S+)\s*(\S.*)$/ or fail("syntax error in md5sums info file: $_");
43     my $zzsum = $1;
44     my $zzfile = $2;
45     $zzfile =~ s,^(\./)?,,;
46     $info_entry{$zzfile} = $zzsum;
47 }
48 close(C);
49
50 # read in conffiles
51 if (-f "control/conffiles") {
52     open(C, '<', "control/conffiles")
53         or fail("cannot open control file conffiles: $!");
54     while (<C>) {
55         chop;
56         next if m/^\s*$/;
57         s,^/,,;
58         $conffile{$_} = 1;
59     }
60     close(C);
61 }
62
63 # Is there a md5sums control file?
64 unless (-f $control) {
65     # ignore if package contains no files
66     return 0 if -z "md5sums";
67
68     # check if package contains non-conffiles
69     # debhelper doesn't create entries in md5sums
70     # for conffiles since this information would
71     # be redundant
72     my $only_conffiles = 1;
73     foreach my $file (keys %info_entry) {
74         unless ($conffile{$file}) {
75             $only_conffiles = 0;
76             last;
77         }
78     }
79
80     tag "no-md5sums-control-file", "" unless $only_conffiles;
81     return 0;
82 }
83
84 # Is it empty? Then skip it. Tag will be issued by control-files
85 if (-z $control) {
86     return 0;
87 }
88
89 # read in md5sums control file
90 open(C, '<', $control)
91     or fail("cannot open md5sums control file $control: $!");
92 while (<C>) {
93     chop;
94     next if m/^\s*$/;
95     if (m{^([a-f0-9]+)\s*(?:\./)?(\S.*)$} && length($1) == 32) {
96         $control_entry{$2} = $1;
97     } else {
98         tag "malformed-md5sums-control-file", "line $.";
99     }
100 }
101 close(C);
102
103 for my $file (keys %control_entry) {
104
105     if (not exists $info_entry{$file}) {
106         tag "md5sums-lists-nonexisting-file", "$file";
107     } elsif ($info_entry{$file} ne $control_entry{$file}) {
108         tag "md5sum-mismatch", "$file";
109     }
110
111     delete $info_entry{$file};
112 }
113 for my $file (keys %info_entry) {
114     tag "file-missing-in-md5sums", "$file"
115         unless ($conffile{$file} || $file =~ m%^var/lib/[ai]spell/.%);
116 }
117
118 }
119
120 1;
121
122 # vim: syntax=perl