diff --git a/xCAT-buildkit/bin/buildkit b/xCAT-buildkit/bin/buildkit index c9c4b6d13..08d3e51e5 100755 --- a/xCAT-buildkit/bin/buildkit +++ b/xCAT-buildkit/bin/buildkit @@ -3892,6 +3892,47 @@ sub NEW_kit_addpkgs } } + + #When using -k -r, there are useless repodir + #delete useless repo dir + my $kitrepodirby=$::base_repodir; + my $cmdby = "/bin/ls $kitrepodirby 2>/dev/null"; + my $outputby = `$cmdby`; + my @allrepolist = split(/\n/, $outputby); + my @dellist; + + foreach my $reponame (@allrepolist) + { + my $match=0; + foreach my $kr (@{$::bldkit_config->{kitrepo}{entries}}) + { + my $repodirname = "$kr->{kitreponame}"; + + if ( ${repodirname} eq ${reponame} ) + { + ${match}++; + } + } + if ( ${match} == 0 ) + { + push(@dellist,$reponame); + } + } + + foreach my $del (@dellist) + { + my $delrepodir=$::base_repodir."/".$del ; + if ( -d $delrepodir ) + { + my $delcmd="rm -Rf $delrepodir"; + if ( system($delcmd) ) + { + print "Failed to delete useless repo directory \n"; + } + } + } + + # Build the full kit tar file my $buildtar_rc = &kit_buildtar;