Skip to content

Commit a1fecf7

Browse files
committed
refactor: only set the latest versions of the packages as installed
1 parent c2f412b commit a1fecf7

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

appimagebuilder/builder/deploy/apt/deploy.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def _prepare_apt_venv(self):
5555
)
5656
# set apt core packages as installed, required for it to properly resolve dependencies
5757
apt_core_packages = self.apt_venv.search_packages(listings.apt_core)
58+
apt_core_packages = self._remove_old_packages(apt_core_packages)
5859
self.apt_venv.set_installed_packages(apt_core_packages)
5960

6061
def _resolve_packages_to_deploy(self, exclude_patterns, package_names):
@@ -80,7 +81,7 @@ def _extract_packages(self, appdir_root, packages):
8081
libc_root = appdir_root / "opt" / "libc"
8182
appdir_root.mkdir(exist_ok=True, parents=True)
8283
libc_root.mkdir(exist_ok=True, parents=True)
83-
libc_packages = self.list_lib_related_packages()
84+
libc_packages = self.list_glibc_related_packages()
8485

8586
for package in packages:
8687
final_target = appdir_root
@@ -94,10 +95,22 @@ def _extract_packages(self, appdir_root, packages):
9495

9596
return packages
9697

97-
def list_lib_related_packages(self):
98+
def list_glibc_related_packages(self):
9899
initial_libc_packages = []
99100
for pkg_name in listings.glibc:
100101
for arch in self.apt_venv.architectures:
101102
initial_libc_packages.append("%s:%s" % (pkg_name, arch))
102103
libc_packages = self.apt_venv.install_simulate(initial_libc_packages)
103104
return libc_packages
105+
106+
def _remove_old_packages(self, apt_core_packages):
107+
latest_packages = {}
108+
for package in apt_core_packages:
109+
pkg_tuple = (package.name, package.arch)
110+
if pkg_tuple not in latest_packages:
111+
latest_packages[pkg_tuple] = package
112+
else:
113+
if package > latest_packages[pkg_tuple]:
114+
latest_packages[pkg_tuple] = package
115+
116+
return latest_packages.values()

appimagebuilder/builder/deploy/apt/package.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# all copies or substantial portions of the Software.
1212
import urllib
1313

14+
from packaging import version
15+
1416

1517
class Package:
1618
def __init__(self, name, version, arch):
@@ -54,5 +56,9 @@ def __str__(self):
5456
output = "%s=%s" % (output, self.version)
5557
return output
5658

59+
def __gt__(self, other):
60+
if isinstance(other, Package):
61+
return version.parse(self.version) > version.parse(other.version)
62+
5763
def __hash__(self):
5864
return self.__str__().__hash__()

appimagebuilder/builder/deploy/apt/venv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,6 @@ def search_packages(self, names):
270270

271271
# empty lines indicate the end of a package description block
272272
if pkg_name:
273-
packages.append(Package(pkg_name, pkg_version, pkg_arch))
273+
packages.append(Package(pkg_name, pkg_version, pkg_arch))
274274

275275
return packages

0 commit comments

Comments
 (0)