From bea2957889c182c9912956342f24c08276256128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Sat, 24 Feb 2024 14:15:09 +0100 Subject: [PATCH] Save transactions to array. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolás Ortega Froysa --- pacundo.pl | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/pacundo.pl b/pacundo.pl index e02e187..cfac918 100755 --- a/pacundo.pl +++ b/pacundo.pl @@ -83,6 +83,8 @@ die("Failed to load pacman log file.\n$!"); my $found_txs = 0; my $in_tx = 0; +my @undo_txs; + while ($found_txs < $num_txs && defined(my $line = $pacman_log->readline)) { # Remeber that we're reading this in reverse order if (!$in_tx && $line =~ /\[ALPM\] transaction completed/) { @@ -92,11 +94,23 @@ while ($found_txs < $num_txs && defined(my $line = $pacman_log->readline)) { $found_txs++; $in_tx = 0; } elsif ($line =~ /\[ALPM\] (upgraded|downgraded)/) { - my ($action, $package, $oldver, $newver) = $line =~ /\[ALPM\] (upgraded|downgraded) ([^\s]+) \((.*) -> (.*)\)/; - print("$action $package $oldver -> $newver\n"); + my ($action, $pkg_name, $oldver, $newver) = $line =~ /\[ALPM\] (upgraded|downgraded) ([^\s]+) \((.*) -> (.*)\)/; + push(@undo_txs, + { + 'action' => $action, + 'pkg_name' => $pkg_name, + 'oldver' => $oldver, + 'newver' => $newver, + } + ); } elsif ($line =~ /\[ALPM\] (installed|removed)/) { - my ($action, $package) = $line =~ /\[ALPM\] (installed|removed) ([^\s]+)/; - print("$action $package\n"); + my ($action, $pkg_name) = $line =~ /\[ALPM\] (installed|removed) ([^\s]+)/; + push(@undo_txs, + { + 'action' => $action, + 'pkg_name' => $pkg_name, + } + ); } } }