Debian Codegraph @

development/check-contents

raw
1 #!/usr/bin/perl
2 # wget http://ftp.it.debian.org/debian/dists/unstable/main/Contents-amd64.gz
3
4 use warnings;
5 use strict;
6 use autodie;
7 use feature qw(say);
8
9 use Storable;
10
11 my $data = read_data();
12
13 my (@l1, @l2);
14
15 # check all files in /bin /sbin /lib
16 foreach (@{$data->{rootfiles}}) {
17 my ($name, $pkg) = @$_;
18
19 # is there one in /usr too?
20 next unless exists $data->{files}->{'usr/' . $name};
21 my $usrpkg = $data->{files}->{'usr/' . $name};
22
23 # and are they in the same package?
24 if ($pkg eq $usrpkg) {
25 push(@l1, [ $name, $pkg ]);
26 } else {
27 push(@l2, [ $name, $pkg, $usrpkg ]);
28 }
29 }
30
31 say 'Single packages shipping the same file in / and /usr:';
32 say "$_->[1]\t$_->[0]" foreach sort { $a->[1] cmp $b->[1] } @l1;
33
34 say '';
35 say 'Multiple packages shipping the same file in / and /usr:';
36 say "$_->[1]\t$_->[0]\t$_->[2]" foreach sort { $a->[1] cmp $b->[1] } @l2;
37
38 exit 0;
39
40 ##############################################################################
41 sub read_data {
42 my $cachefile = '/tmp/contents.storable';
43
44 return retrieve($cachefile) if -e $cachefile;
45
46 my $data = read_contents();
47 store($data, $cachefile);
48 return $data;
49 }
50
51 sub read_contents {
52 my (@rootfiles, %files);
53
54 open(my $fh, 'zcat Contents-amd64.gz |');
55 while (<$fh>) {
56 my ($file, $package) = split;
57 $package =~ s#(^|,)[a-z]+/#$1#g;
58
59 if ($file =~ m#^(?:s?bin|lib|libx?32|lib64)/#) {
60 push(@rootfiles, [$file, $package]);
61 } elsif ($file =~ m#^usr/#) {
62 if (exists $files{$file}) {
63 $files{$file} = $files{$file} . ',' . $package;
64 } else {
65 $files{$file} = $package;
66 }
67 }
68 }
69 close($fh) or die "close: $!";
70
71 return { rootfiles => \@rootfiles, files => \%files };
72 }
73