From 6877e5fc2846c54c6739ecbdd779d7e6092154fb Mon Sep 17 00:00:00 2001 From: Pascal Terjan Date: Fri, 20 Jan 2023 19:45:49 +0000 Subject: iurt: Cleanup some duplicated code --- lib/Iurt/Urpmi.pm | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/lib/Iurt/Urpmi.pm b/lib/Iurt/Urpmi.pm index 2343ee8..62156e3 100644 --- a/lib/Iurt/Urpmi.pm +++ b/lib/Iurt/Urpmi.pm @@ -445,6 +445,18 @@ sub install_packages { $ok; } +sub get_srpm_name { + my ($run, $config, $chroot_tmp, $srpm, $luser, $spec) = @_; + if (!perform_command(qq(chroot $chroot_tmp su $luser -c "rpmspec -q --qf %{NVR}.src.rpm --srpm /home/$luser/rpmbuild/SPECS/$spec > /home/$luser/rpmbuild/SPECS/$spec.srpm_name"), + $run, $config, + use_iurt_root_command => 1, + hash => "identify_$srpm")) { + plog("ERROR: failed to get the name of the generated src.rpm"); + return; + } + return cat_("$chroot_tmp/home/$luser/rpmbuild/SPECS/$spec.srpm_name"); +} + # return ("exit_code", srpm, spec) sub recreate_srpm { my ($_self, $run, $config, $chroot_tmp, $dir, $srpm, $luser, $b_retry) = @_; @@ -526,14 +538,7 @@ sub recreate_srpm { # return 0 unless $ret; - if (!perform_command(qq(chroot $chroot_tmp su $luser -c "rpmspec -q --qf %{NVR}.src.rpm --srpm /home/$luser/rpmbuild/SPECS/$spec > /home/$luser/rpmbuild/SPECS/$spec.srpm_name"), - $run, $config, - use_iurt_root_command => 1, - hash => "identify_$srpm")) { - plog("ERROR: failed to get the name of the generated src.rpm"); - return; - } - my $new_srpm = cat_("$chroot_tmp/home/$luser/rpmbuild/SPECS/$spec.srpm_name"); + my $new_srpm = get_srpm_name($run, $config, $chroot_tmp, $srpm, $luser, $spec); if (!$new_srpm) { plog("ERROR: failed to get the name of the generated src.rpm"); return; @@ -553,7 +558,6 @@ sub recreate_srpm { ($ret, "$prefix$new_srpm", $spec); } -# return ("exit_code", srpm, spec) sub install_dynamic_buildrequires { my ($self, $run, $config, $chroot_tmp, $luser, $spec, $srpm) = @_; my $program_name = $run->{program_name}; @@ -566,14 +570,7 @@ sub install_dynamic_buildrequires { return 1; } - if (!perform_command(qq(chroot $chroot_tmp su $luser -c "rpmspec -q --qf %{NVR}.src.rpm --srpm /home/$luser/rpmbuild/SPECS/$spec > /home/$luser/rpmbuild/SPECS/$spec.srpm_name"), - $run, $config, - use_iurt_root_command => 1, - hash => "identify_$srpm")) { - plog("ERROR: failed to get the name of the generated src.rpm"); - return; - } - my $new_srpm = cat_("$chroot_tmp/home/$luser/rpmbuild/SPECS/$spec.srpm_name"); + my $new_srpm = get_srpm_name($run, $config, $chroot_tmp, $srpm, $luser, $spec); if (!$new_srpm) { plog("ERROR: failed to get the name of the generated src.rpm"); return; -- cgit v1.2.1