Verified Commit 25574fdb authored by Karel Koci's avatar Karel Koci 🤘

Fix check for installed packages and removed package

Updater preserves removed packages in index if they at time of removal
had some modified configuration files. Such packages are removed and
should be reported as such. There is also no control file on filesystem.

This fixes missing control file error by just not reading control file
if it is not present. This has no impact as info is not available about
that package and should not be required anyway.

This also fixes installed method by properly checking status fields.
parent ad614865
......@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Fixed
- `packages` module failure when there is uninstalled package in index
## [1.4.2] - 2020-12-01
### Fixed
- Missing defaults for `--rand-sleep` and `--wait-for-network` arguments
......
......@@ -67,11 +67,13 @@ class Package:
self._add_field(name, value)
if "Package" not in self._fields:
return # Can't continue
with open(pathlib.Path(rootdir) / "/usr/lib/opkg/info/" / (self._fields["Package"] + ".control"), "r") as file:
for line in file:
name, value = self._parse_field(line)
if name not in self._fields:
self._add_field(name, value)
control_file = pathlib.Path(rootdir) / "/usr/lib/opkg/info/" / (self._fields["Package"] + ".control")
if control_file.exists():
with open(control_file, "r") as file:
for line in file:
name, value = self._parse_field(line)
if name not in self._fields:
self._add_field(name, value)
def __getitem__(self, key):
return self._fields[key]
......@@ -82,6 +84,12 @@ class Package:
def __iter__(self):
return iter(self._fields)
def is_installed(self):
"""Just simple existence of package does not ensure it is installed. It can be in some broken state or kept for
system consistency while being in reality mostly removed. This function checks if package is fully installed.
"""
return self._fields["Status"][2] == "installed"
class Status(collections.abc.Mapping):
"""Abstraction on top of /usr/lib/opkg/status file.
......@@ -112,10 +120,10 @@ class Status(collections.abc.Mapping):
It returns tuple of all package names.
"""
res = []
if package in self._packages:
if package in self._packages and self._packages[package].is_installed():
res.append(package)
for name, pkg in self._packages.items():
if "Provides" in pkg and package in pkg["Provides"]:
if pkg.is_installed() and "Provides" in pkg and package in pkg["Provides"]:
res.append(name)
return tuple(res)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment