Index: post-build-checks-1.0/checks/09-check-packaged-twice =================================================================== --- post-build-checks-1.0.orig/checks/09-check-packaged-twice 2011-10-20 11:57:54.000000000 +0200 +++ post-build-checks-1.0/checks/09-check-packaged-twice 2011-11-28 12:46:09.048680204 +0100 @@ -1,61 +1,74 @@ -#!/usr/bin/perl +#!/usr/bin/perl -w # search for files packaged more than once +# it is an error if such a file exists but the packages do not conflict # use strict; my $had_errors = 0; -my $build_root = $::ENV{BUILD_ROOT}; -my @RPMS = (); +my $build_root = $::ENV{BUILD_ROOT} || '/'; my $TOPDIR = '/usr/src/packages'; $TOPDIR = '/.build.packages' if -d "$build_root/.build.packages"; -open ( ALL_RPMS , "find $build_root$TOPDIR/RPMS -name \"*.rpm\" |"); -while ( my $cur = ) { - chomp ( $cur ); - $cur =~ s/^$build_root//; - push @RPMS, $cur; +sub conflicts { + my ($rpm1, $rpm2) = @_; + open (F, "chroot $build_root rpm -qp --qf '[%{CONFLICTNAME} %{CONFLICTFLAGS} %{CONFLICTVERSION}\n]' $rpm1|"); + my @conflicts = ; + close F; + chomp @conflicts; + return 0 unless @conflicts; + open (F, "chroot $build_root rpm -qp --qf '[%{PROVIDENAME} %{PROVIDEFLAGS} %{PROVIDEVERSION}\n]' $rpm2|"); + my @provides = ; + close F; + for my $c (@conflicts) { + my @cc = split(' ', $c, 3); + $cc[0] =~ s/^otherproviders\((.*)\)$/$1/; + for my $p (@provides) { + my @pp = split(' ', $p, 3); + next unless $cc[0] eq $pp[0]; + # add complex logic here if needed + return 1; + } + } + return 0; } -close ( ALL_RPMS ); -if ( $#RPMS < 1 ) { - exit 0; +open (ALL_RPMS, "find $build_root$TOPDIR/RPMS -name \"*.rpm\" |"); +my @rpms = ; +chomp @rpms; +close ALL_RPMS; + +exit 0 if @rpms < 2; + +my %allfiles; +my %pkg2rpm; + +for my $rpm (@rpms) { + $rpm =~ s/^$build_root//; + open (FILES, "chroot $build_root rpm -qp --qf '[%{FILEMODES:perms} F:%{FILEFLAGS:fflags} %{NAME} %{FILENAMES}\n]' $rpm|"); + my @files = ; + chomp @files; + close FILES; + # ignore dirs + @files = grep {!/^d/} @files; + for my $file (@files) { + next unless $file =~ /^\S+ F:(\S*) (\S+) (.*)$/; + $allfiles{$3}->{$2} = $1; + $pkg2rpm{$2} = $rpm; + } } -my %FILES = (); - -for my $cur (@RPMS) { - my $rpmname = `chroot $build_root rpm -qp --qf '%{NAME}' $cur`; - open ( FILELIST , "chroot $build_root rpm -qplv $cur |"); - while ( my $file = ) { - chomp ( $file ); - next if ( $file =~ /^d/ ); - my @line = split ('\s+',$file); - my $filename = ""; - while (my $file_too = pop(@line)) { - if ($file_too eq "->") { - # this was a symlink target - $filename = ""; - } else { - $filename = $file_too.($filename eq "" ? "" : " ").$filename; - } - last if ($#line == 7); - } - if ( $FILES{$filename} ) { - #printf "ERROR: $rpmname: $filename already packaged in package $FILES{$filename}\n"; - printf "WARNING: $rpmname: $filename already packaged in package $FILES{$filename}\n"; - $had_errors = 1; - $FILES{$filename} .= ",$rpmname"; - } else { - $FILES{$filename} = $rpmname; - } - } - close ( FILELIST ); +for my $file (keys %allfiles) { + my @pkgs = keys %{$allfiles{$file}}; + next if @pkgs < 2; + while (@pkgs) { + my $p1 = shift @pkgs; + for my $p2 (@pkgs) { + next if (index('g', $allfiles{$file}->{$p1}) != -1) && (index('g', $allfiles{$file}->{$p2}) != -1); + next if conflicts($pkg2rpm{$p1}, $pkg2rpm{$p2}) || conflicts($pkg2rpm{$p2}, $pkg2rpm{$p1}); + print "ERROR: $file is packaged in both $p1 and $p2, and the packages do not conflict\n"; + $had_errors = 1; + } + } } -#if ( $had_errors ) { -# printf "found ERRORS\n"; -# exit 1; -#} - -exit 0; - +exit $had_errors;