[PATCH] libopkg: add pre-depends print to package status dumps

9 views
Skip to first unread message

Shruthi Ravichandran

unread,
Mar 7, 2022, 5:01:45 PM3/7/22
to opkg-...@googlegroups.com, Shruthi Ravichandran
opkg installs a package's pre-dependencies but does not record them
in the package's status file. Due to this, opkg allows uninstallation
of an installed package's pre-dependency when it should complain.
This patch fixes that by adding the pre-depends print to the
package's status file. It also adds the pre-depends print to the
package's status info dump.

Additionally, this patch also adds a missing break in a switch case
while parsing a package's dependencies. This was causing a package's
pre-dependency to be added twice to the solvable, each time with a
different marker.

Given installed packages 'a' and 'b', where 'a'--'pre-depends'-->'b',
the following is the opkg output (after the patch is applied) when
asked to uninstall package 'b' before uninstalling 'a':

DEBUG cmd: /mnt/workspace/src/opkg -o /tmp/opkg --force-postinstall remove b
DEBUG stdout: * Solver encountered 1 problem(s):
* Problem 1/1:
* - package a-1.0.all requires b, but none of the providers can be installed
* - conflicting requests
* - problem with installed package a-1.0.all
*
* Solution 1:
* - allow deinstallation of a-1.0.all

* Solution 2:
* - do not ask to deinstall b

* - do not ask to deinstall b

Signed-off-by: Shruthi Ravichandran <shruthi.ra...@ni.com>
---
libopkg/pkg.c | 19 ++++++++++++++++++-
libopkg/solvers/libsolv/opkg_solver_libsolv.c | 1 +
2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/libopkg/pkg.c b/libopkg/pkg.c
index db10ccf..88012fa 100644
--- a/libopkg/pkg.c
+++ b/libopkg/pkg.c
@@ -711,7 +711,22 @@ static void pkg_formatted_field(FILE * fp, pkg_t * pkg, const char *field, const
}
fprintf(fp, "\n");
}
- } else {
+ }
+ else if (strcasecmp(field, "Pre-Depends") == 0) {
+ if (pkg->pre_depends_count) {
+ fprintf(fp, "Pre-Depends:");
+ for (j = 0, i = 0; i < depends_count; i++) {
+ if (pkg->depends[i].type != PREDEPEND)
+ continue;
+ str = pkg_depend_str(pkg, i);
+ fprintf(fp, "%s %s", j == 0 ? "" : ",", str);
+ free(str);
+ j++;
+ }
+ fprintf(fp, "\n");
+ }
+ }
+ else {
goto UNKNOWN_FMT_FIELD;
}
break;
@@ -858,6 +873,7 @@ void pkg_formatted_info(FILE * fp, pkg_t * pkg, const char *fields_filter)
pkg_formatted_field(fp, pkg, "Package", NULL);
pkg_formatted_field(fp, pkg, "Version", fields_filter);
pkg_formatted_field(fp, pkg, "Depends", fields_filter);
+ pkg_formatted_field(fp, pkg, "Pre-Depends", fields_filter);
pkg_formatted_field(fp, pkg, "Recommends", fields_filter);
pkg_formatted_field(fp, pkg, "Suggests", fields_filter);
pkg_formatted_field(fp, pkg, "Provides", fields_filter);
@@ -896,6 +912,7 @@ void pkg_print_status(pkg_t * pkg, FILE * file)
pkg_formatted_field(file, pkg, "Package", NULL);
pkg_formatted_field(file, pkg, "Version", NULL);
pkg_formatted_field(file, pkg, "Depends", NULL);
+ pkg_formatted_field(file, pkg, "Pre-Depends", NULL);
pkg_formatted_field(file, pkg, "Recommends", NULL);
pkg_formatted_field(file, pkg, "Suggests", NULL);
pkg_formatted_field(file, pkg, "Provides", NULL);
diff --git a/libopkg/solvers/libsolv/opkg_solver_libsolv.c b/libopkg/solvers/libsolv/opkg_solver_libsolv.c
index d442d3d..936bea7 100644
--- a/libopkg/solvers/libsolv/opkg_solver_libsolv.c
+++ b/libopkg/solvers/libsolv/opkg_solver_libsolv.c
@@ -416,6 +416,7 @@ static void pkg2solvable(pkg_t *pkg, Solvable *solvable_out, int installed)
solvable_out->requires = repo_addid_dep(repo,
solvable_out->requires, dependId,
SOLVABLE_PREREQMARKER);
+ break;
case DEPEND:
opkg_msg(DEBUG2, "%s depends %s\n", pkg->name,
pool_dep2str(pool, dependId));
--
2.20.1

Alex Stewart

unread,
Mar 9, 2022, 8:21:04 AM3/9/22
to Shruthi Ravichandran, opkg-...@googlegroups.com
Hey Shruthi,

The patch contents look good to me. Thanks for fixing up the status file.

Can you break apart the `pkg.c` and `opkg_solver_libsolv.c` changes into
different commits? Unless I'm mistaken, they are independent fixes; right?

Thanks,
Alex Stewart
Software Engineer - NI Real-Time OS
NI (National Instruments)

alex.s...@ni.com

Alex Stewart

unread,
Mar 9, 2022, 8:22:48 AM3/9/22
to Shruthi Ravichandran, opkg-...@googlegroups.com
Forgot to add in my last email: here's the results of the test pipeline
I ran on the patchset.

https://gitlab.com/astewart.49c6/opkg/-/pipelines/488075153

Shruthi Ravichandran

unread,
Mar 9, 2022, 3:29:29 PM3/9/22
to alex.s...@ni.com, opkg-...@googlegroups.com, Shruthi Ravichandran
opkg installs a package's pre-dependencies but does not record them
in the package's status file. Due to this, opkg allows uninstallation
of an installed package's pre-dependency when it should complain.
This patch fixes that by adding the pre-depends print to the
package's status file. It also adds the pre-depends print to the
package's status info dump.

Given installed packages 'a' and 'b', where 'a'--'pre-depends'-->'b',
the following is the opkg output (after the patch is applied) when
asked to uninstall package 'b' before uninstalling 'a':

DEBUG cmd: /mnt/workspace/src/opkg -o /tmp/opkg --force-postinstall remove b
DEBUG stdout: * Solver encountered 1 problem(s):
* Problem 1/1:
* - package a-1.0.all requires b, but none of the providers can be installed
* - conflicting requests
* - problem with installed package a-1.0.all
*
* Solution 1:
* - allow deinstallation of a-1.0.all

* Solution 2:
* - do not ask to deinstall b

* - do not ask to deinstall b

Signed-off-by: Shruthi Ravichandran <shruthi.ra...@ni.com>
---
libopkg/pkg.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
--
2.20.1

Shruthi Ravichandran

unread,
Mar 9, 2022, 3:29:46 PM3/9/22
to alex.s...@ni.com, opkg-...@googlegroups.com, Shruthi Ravichandran
This patch adds a missing break in a switch case while parsing a
package's dependencies. This was causing a package's pre-dependency
to be added twice to the solvable, each time with a different marker.

Signed-off-by: Shruthi Ravichandran <shruthi.ra...@ni.com>
---
libopkg/solvers/libsolv/opkg_solver_libsolv.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/libopkg/solvers/libsolv/opkg_solver_libsolv.c b/libopkg/solvers/libsolv/opkg_solver_libsolv.c
index d442d3d..936bea7 100644
--- a/libopkg/solvers/libsolv/opkg_solver_libsolv.c
+++ b/libopkg/solvers/libsolv/opkg_solver_libsolv.c
@@ -416,6 +416,7 @@ static void pkg2solvable(pkg_t *pkg, Solvable *solvable_out, int installed)
solvable_out->requires = repo_addid_dep(repo,
solvable_out->requires, dependId,
SOLVABLE_PREREQMARKER);
+ break;
case DEPEND:
opkg_msg(DEBUG2, "%s depends %s\n", pkg->name,
pool_dep2str(pool, dependId));
--
2.20.1

Alex Stewart

unread,
Mar 10, 2022, 12:40:57 PM3/10/22
to Shruthi Ravichandran, opkg-...@googlegroups.com
Merged as commit 592e4aec0b92f5ea1f7f871004afd2d8a1b93b93 and parent [1].

[1]
https://git.yoctoproject.org/opkg/commit/?id=592e4aec0b92f5ea1f7f871004afd2d8a1b93b93

Thanks,
Reply all
Reply to author
Forward
0 new messages