From ec1ef81ea8f44807c07118872aabb43372907972 Mon Sep 17 00:00:00 2001 From: baiyuan Date: Fri, 31 Oct 2014 04:40:09 -0400 Subject: [PATCH] fix defect 4349 [dev]after rmkit/rmkitcomp -i kitcomp list, kitrepo dir in otherpkgdir is not deleted --- xCAT-server/lib/xcat/plugins/kit.pm | 58 ++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/xCAT-server/lib/xcat/plugins/kit.pm b/xCAT-server/lib/xcat/plugins/kit.pm index e3e96804b..c8f08846e 100644 --- a/xCAT-server/lib/xcat/plugins/kit.pm +++ b/xCAT-server/lib/xcat/plugins/kit.pm @@ -2776,7 +2776,9 @@ sub rmkitcomp if ( !$match ) { if ( $debianflag ) { - system("umount -f $otherpkgdir/$kitcomps{$kitcomponent}{kitreponame}"); + #Now we do not use moun --bind for kitrepo dir to otherpkgdir + #leave this line is support old way when using mount + system("umount -f $otherpkgdir/$kitcomps{$kitcomponent}{kitreponame} > /dev/null"); } system("rm -rf $otherpkgdir/$kitcomps{$kitcomponent}{kitreponame}"); } @@ -3249,6 +3251,60 @@ sub rmkitcomp # Write osimage table with all the above udpates. $tabs{osimage}->setAttribs({imagename => $osimage }, \%{$osimagetable} ); + #After all the data updated in osimage and linuximage table + #check if these kitcomponents are assigned to other osimage + #if these kitcomponents are not used by other osimage, find their kitrepo and kitrepo directory under otherpkg dir + #delete these kitrepo + my @allosikitcomps = $tabs{osimage}->getAllAttribs( 'imagename', 'kitcomponents' ); + + (my $linuximagetable) = $tabs{linuximage}->getAttribs({imagename=> $osimage}, 'postinstall', 'exlist', 'otherpkglist', 'otherpkgdir', 'driverupdatesrc'); + if ( $linuximagetable and $linuximagetable->{otherpkgdir} ) { + + my $otherpkgdir = $linuximagetable->{otherpkgdir}; + foreach my $kitcomponent (keys %kitcomps) { + + my %newosikitcomponents; + foreach my $allosikitcomp (@allosikitcomps) { + if ( $allosikitcomp->{kitcomponents} and $allosikitcomp->{imagename} ) { + my @allkitcomps = split /,/, $allosikitcomp->{kitcomponents}; + foreach my $allkitcomp ( @allkitcomps ) { + if ( $allosikitcomp->{imagename} ne $osimage or $allkitcomp ne $kitcomponent ) { + $newosikitcomponents{$allkitcomp} = 1; + } + } + } + } + + if ( $kitcomps{$kitcomponent}{kitreponame} ) { + if ( -d "$otherpkgdir/$kitcomps{$kitcomponent}{kitreponame}" ) { + + # Check if this repo is used by other kitcomponent before removing the link + my $match = 0; + foreach my $osikitcomp ( keys %newosikitcomponents ) { + + my $depkitrepodir; + (my $kitcomptable) = $tabs{kitcomponent}->getAttribs({kitcompname => $osikitcomp}, 'kitreponame'); + if ( $kitcomptable and $kitcomptable->{kitreponame} ) { + $depkitrepodir = "$otherpkgdir/$kitcomptable->{kitreponame}"; + } + if ( $depkitrepodir =~ /^$otherpkgdir\/$kitcomps{$kitcomponent}{kitreponame}$/) { + $match = 1; + } + } + if ( !$match ) { + if ( $debianflag ) + { + system("umount -f $otherpkgdir/$kitcomps{$kitcomponent}{kitreponame} > /dev/null"); + } + system("rm -rf $otherpkgdir/$kitcomps{$kitcomponent}{kitreponame}"); + } + } + } + } + } + + + return; }