[2/9] pakfire: Replace duplicate code with dblist functioncall

Message ID 20220309225655.4472-3-robin.roevens@disroot.org
State Superseded
Headers
Series pakfire: remove dup. code + seperate ui/logic |

Commit Message

Robin Roevens March 9, 2022, 10:56 p.m. UTC
  Replace pakfire install code duplicating dblist working with call
to actual dblist function.

Signed-off-by: Robin Roevens <robin.roevens@disroot.org>
---
 src/pakfire/pakfire | 38 +++++++++++++-------------------------
 1 file changed, 13 insertions(+), 25 deletions(-)
  

Comments

Michael Tremer March 21, 2022, 4:20 p.m. UTC | #1
This looks good to me.

> On 9 Mar 2022, at 22:56, Robin Roevens <robin.roevens@disroot.org> wrote:
> 
> Replace pakfire install code duplicating dblist working with call
> to actual dblist function.
> 
> Signed-off-by: Robin Roevens <robin.roevens@disroot.org>
> ---
> src/pakfire/pakfire | 38 +++++++++++++-------------------------
> 1 file changed, 13 insertions(+), 25 deletions(-)
> 
> diff --git a/src/pakfire/pakfire b/src/pakfire/pakfire
> index b4930e85d..f23110cf5 100644
> --- a/src/pakfire/pakfire
> +++ b/src/pakfire/pakfire
> @@ -107,42 +107,30 @@
> 		### Make sure that the list is not outdated.
> 		&Pakfire::dbgetlist("noforce");
> 
> -		open(FILE, "<$Conf::dbdir/lists/packages_list.db");
> -		my @db = <FILE>;
> -		close(FILE);
> +		my %paklist = &Pakfire::dblist("all");
> 
> 		my $dep;
> 		my @deps;
> 		my $pak;
> 		my @paks;
> 		my @temp;
> -		my @templine;
> -		my $found = 0;
> 		my $return;
> 		my @all;
> 		foreach $pak (@ARGV) {
> 			unless ("$pak" =~ "^-") {
> -				$return = &Pakfire::isinstalled($pak);
> -				if ($return eq 0) {
> -					&Pakfire::message("PAKFIRE INFO: $pak is already installed");
> -					next;
> -				}
> -				$found = 0;
> -				foreach (@db) {
> -					@templine = split(/;/,$_);
> -					if ("$templine[0]" eq "$pak" ) {
> -						push(@paks,$pak);
> -						push(@all,$pak);
> -						@temp = &Pakfire::resolvedeps("$pak");
> -						foreach $dep (@temp) {
> -							push(@deps,$dep) if $dep;
> -							push(@all,$dep) if $dep;
> -						}
> -						$found = 1;
> -						break;
> +				if (defined $paklist{$pak}) {
> +					if ("$paklist{$pak}{'Installed'}" eq "yes") {
> +						&Pakfire::message("PAKFIRE INFO: $pak is already installed");
> +						next;
> 					}
> -				}
> -				if ($found == 0) {
> +					push(@paks,$pak);
> +					push(@all,$pak);
> +					@temp = &Pakfire::resolvedeps("$pak");
> +					foreach $dep (@temp) {
> +						push(@deps,$dep) if $dep;
> +						push(@all,$dep) if $dep;
> +					}
> +				} else {
> 					&Pakfire::message("");
> 					&Pakfire::message("PAKFIRE WARN: The pak \"$pak\" is not known. Please try running \"pakfire update\".");
> 				}
> -- 
> 2.34.1
> 
> 
> -- 
> Dit bericht is gescanned op virussen en andere gevaarlijke
> inhoud door MailScanner en lijkt schoon te zijn.
>
  

Patch

diff --git a/src/pakfire/pakfire b/src/pakfire/pakfire
index b4930e85d..f23110cf5 100644
--- a/src/pakfire/pakfire
+++ b/src/pakfire/pakfire
@@ -107,42 +107,30 @@ 
 		### Make sure that the list is not outdated.
 		&Pakfire::dbgetlist("noforce");
 
-		open(FILE, "<$Conf::dbdir/lists/packages_list.db");
-		my @db = <FILE>;
-		close(FILE);
+		my %paklist = &Pakfire::dblist("all");
 
 		my $dep;
 		my @deps;
 		my $pak;
 		my @paks;
 		my @temp;
-		my @templine;
-		my $found = 0;
 		my $return;
 		my @all;
 		foreach $pak (@ARGV) {
 			unless ("$pak" =~ "^-") {
-				$return = &Pakfire::isinstalled($pak);
-				if ($return eq 0) {
-					&Pakfire::message("PAKFIRE INFO: $pak is already installed");
-					next;
-				}
-				$found = 0;
-				foreach (@db) {
-					@templine = split(/;/,$_);
-					if ("$templine[0]" eq "$pak" ) {
-						push(@paks,$pak);
-						push(@all,$pak);
-						@temp = &Pakfire::resolvedeps("$pak");
-						foreach $dep (@temp) {
-							push(@deps,$dep) if $dep;
-							push(@all,$dep) if $dep;
-						}
-						$found = 1;
-						break;
+				if (defined $paklist{$pak}) {
+					if ("$paklist{$pak}{'Installed'}" eq "yes") {
+						&Pakfire::message("PAKFIRE INFO: $pak is already installed");
+						next;
 					}
-				}
-				if ($found == 0) {
+					push(@paks,$pak);
+					push(@all,$pak);
+					@temp = &Pakfire::resolvedeps("$pak");
+					foreach $dep (@temp) {
+						push(@deps,$dep) if $dep;
+						push(@all,$dep) if $dep;
+					}
+				} else {
 					&Pakfire::message("");
 					&Pakfire::message("PAKFIRE WARN: The pak \"$pak\" is not known. Please try running \"pakfire update\".");
 				}