Obtain package files for installation.

Signed-off-by: Nicolás Ortega Froysa <nicolas@ortegas.org>
This commit is contained in:
Nicolás A. Ortega Froysa 2024-04-26 09:45:37 +02:00
parent c08a9f4b40
commit d90016fd8c

View File

@ -160,6 +160,19 @@ sub get_pkgmgr() {
return \%pkgmgr; return \%pkgmgr;
} }
sub find_local_pkg($pkgmgr, $pkg_name, $pkg_ver) {
my $pkg_file = '';
my $aur_dir = "$ENV{'XDG_CACHE_HOME'}/yay/$pkg_name";
if ($pkgmgr->{name} eq 'yay' && -d $aur_dir) {
$pkg_file = `ls $aur_dir/$pkg_name-$pkg_ver-*.pkg.tar.zst | tail -n1`;
} else {
$pkg_file = `ls /var/cache/pacman/pkg/$pkg_name-$pkg_ver-*.pkg.tar.zst | tail -n1`;
}
return $pkg_file;
}
getopts("irt:dvh", \my %opts); getopts("irt:dvh", \my %opts);
if ($opts{'v'}) { if ($opts{'v'}) {
@ -186,3 +199,23 @@ my @undo_txs = &read_txs($num_txs);
# Interactive mode # Interactive mode
@undo_txs = &select_txs(@undo_txs) unless ($r_flag); @undo_txs = &select_txs(@undo_txs) unless ($r_flag);
my $remove_pkgs = ""; # executed via -R
my $remote_install_pkgs = ""; # executed via -S
my $local_install_pkgs = ""; # executed via -U
foreach my $tx (@undo_txs) {
if ($tx->{action} eq 'installed') {
$remove_pkgs .= "$tx->{pkg_name} ";
} elsif ($tx->{action} eq 'removed') {
# TODO: install local package if available
$remote_install_pkgs .= "$tx->{pkg_name} ";
} else {
my $pkg_file = &find_local_pkg($pkgmgr, $tx->{pkg_name}, $tx->{oldver});
if ($pkg_file eq '') {
$remote_install_pkgs .= "$tx->{pkg_name} ";
} else {
$local_install_pkgs .= "$pkg_file ";
}
}
}