diff options
| author | Julian Andres Klode <julian.klode@canonical.com> | 2024-09-05 14:56:01 +0200 |
|---|---|---|
| committer | Julian Andres Klode <julian.klode@canonical.com> | 2024-11-11 12:30:01 +0100 |
| commit | 49d3d6b2c3dbc0d30e46131dd288f4e106ea2fe6 (patch) | |
| tree | 18eac389bda24ae130426c7f802be309900083c6 /test/interactive-helper | |
| parent | 09e853dd424a6ab53bd5791de75894a985968399 (diff) | |
Fix keeping back removals of obsolete packages
ResolveByKeepInternal() inadvertently considered packages that were
marked for removals as not being possible to keep back, but that's
not true, all they need is to have a currently installed version.
The test case is a bit awkward to construct because our upgrade code
doesn't get into a place where this happens that we know off. Or maybe
it does with phased upgrades, but here we simplify this by using a
helper binary that dumps state, marks for removal, and then calls
ResolveByKeep and checks the removal is undone.
LP: #2078720
Diffstat (limited to 'test/interactive-helper')
| -rw-r--r-- | test/interactive-helper/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | test/interactive-helper/testkeep.cc | 57 |
2 files changed, 59 insertions, 0 deletions
diff --git a/test/interactive-helper/CMakeLists.txt b/test/interactive-helper/CMakeLists.txt index 8e8764353..bfca6c8f6 100644 --- a/test/interactive-helper/CMakeLists.txt +++ b/test/interactive-helper/CMakeLists.txt @@ -14,6 +14,8 @@ add_executable(mthdcat mthdcat.cc) target_link_libraries(mthdcat ${APTPKG_LIB}) add_executable(testdeb testdeb.cc) target_link_libraries(testdeb ${APTPKG_LIB}) +add_executable(testkeep testkeep.cc) +target_link_libraries(testkeep ${APTPKG_LIB}) add_executable(extract-control extract-control.cc) target_link_libraries(extract-control ${APTPKG_LIB}) add_executable(aptwebserver aptwebserver.cc) diff --git a/test/interactive-helper/testkeep.cc b/test/interactive-helper/testkeep.cc new file mode 100644 index 000000000..f65f43203 --- /dev/null +++ b/test/interactive-helper/testkeep.cc @@ -0,0 +1,57 @@ +#include <config.h> + +#include <apt-pkg/init.h> +#include <apt-pkg/algorithms.h> +#include <apt-pkg/cachefile.h> +#include <apt-pkg/error.h> +#include <apt-pkg/pkgsystem.h> +#include <apt-pkg/prettyprinters.h> + +#include <iostream> +#include <string> + +static bool test(const char *name, bool hold) +{ + pkgCacheFile cache; + if (not cache.Open()) + return false; + + for (auto Pkg = cache->PkgBegin(); Pkg.end() == false; ++Pkg) + std::cout << "A: " << APT::PrettyPkg(cache, Pkg) << std::endl; + + cache->MarkDelete(cache->FindPkg(name)); + if (hold) + cache->MarkProtected(cache->FindPkg(name)); + + for (auto Pkg = cache->PkgBegin(); Pkg.end() == false; ++Pkg) + std::cout << "B: " << APT::PrettyPkg(cache, Pkg) << std::endl; + + pkgProblemResolver resolve(cache); + bool res = resolve.ResolveByKeep(); + + for (auto Pkg = cache->PkgBegin(); Pkg.end() == false; ++Pkg) + std::cout << "C: " << APT::PrettyPkg(cache, Pkg) << std::endl; + + return res; +} + +int main(int argc, const char *argv[]) +{ + if (argc != 2 && argc != 3) + { + return _error->Error("Expected one argument"); + goto err; + } + if (not pkgInitConfig(*_config)) + goto err; + if (not pkgInitSystem(*_config, _system)) + goto err; + if (not test(argv[1], argc > 2 && strcmp(argv[2], "--hold") == 0)) + goto err; + + return 0; +err: + _error->DumpErrors(); + return 1; +} + |
