This is the mail archive of the
cygwin-apps
mailing list for the Cygwin project.
[PATCH setup 3/5] Ensure packagedb and underlying solver pool is empty before we read setup.ini
We need to make sure the packagedb is empty if we step backwards to here.
v2:
Also clear solver stored in SolverSolution, which holds a pool pointer
---
ini.cc | 3 +++
libsolv.cc | 22 ++++++++++++++++++++++
libsolv.h | 3 +++
package_db.cc | 14 ++++++++++++++
package_db.h | 1 +
5 files changed, 43 insertions(+)
diff --git a/ini.cc b/ini.cc
index 85325c3..9bd72fb 100644
--- a/ini.cc
+++ b/ini.cc
@@ -347,6 +347,9 @@ do_remote_ini (HWND owner)
static bool
do_ini_thread (HINSTANCE h, HWND owner)
{
+ packagedb db;
+ db.init();
+
bool ini_error = true;
if (source == IDC_SOURCE_LOCALDIR)
ini_error = do_local_ini (owner);
diff --git a/libsolv.cc b/libsolv.cc
index 9dd1eeb..29a26a9 100644
--- a/libsolv.cc
+++ b/libsolv.cc
@@ -316,6 +316,12 @@ void debug_callback(Pool *pool, void *data, int type, const char *str)
}
SolverPool::SolverPool()
+{
+ init();
+}
+
+void
+SolverPool::init()
{
/* create a pool */
pool = pool_create();
@@ -333,6 +339,16 @@ SolverPool::SolverPool()
pool_set_installed(pool, installed->repo);
}
+void
+SolverPool::clear()
+{
+ repos.clear();
+ pool_free(pool);
+ pool = NULL;
+
+ init();
+}
+
SolvRepo *
SolverPool::getRepo(const std::string &name, bool test)
{
@@ -583,6 +599,12 @@ SolverPool::use_test_packages(bool use_test_packages)
// ---------------------------------------------------------------------------
SolverSolution::~SolverSolution()
+{
+ clear();
+}
+
+void
+SolverSolution::clear()
{
if (solv)
{
diff --git a/libsolv.h b/libsolv.h
index 65e1610..cddf76f 100644
--- a/libsolv.h
+++ b/libsolv.h
@@ -130,6 +130,7 @@ class SolverPool
{
public:
SolverPool();
+ void clear();
SolvRepo *getRepo(const std::string &name, bool test = false);
// Utility class for passing arguments to addPackage()
@@ -158,6 +159,7 @@ public:
private:
+ void init();
Id makedeps(Repo *repo, PackageDepends *requires);
Pool *pool;
@@ -236,6 +238,7 @@ class SolverSolution
public:
SolverSolution(SolverPool &_pool) : pool(_pool), solv(NULL) {};
~SolverSolution();
+ void clear();
/* Reset package database to correspond to trans */
void trans2db() const;
diff --git a/package_db.cc b/package_db.cc
index 66e7f0a..8fbec44 100644
--- a/package_db.cc
+++ b/package_db.cc
@@ -47,6 +47,20 @@ packagedb::packagedb ()
{
}
+void
+packagedb::init ()
+{
+ installeddbread = 0;
+ installeddbver = 0;
+ packages.clear();
+ sourcePackages.clear();
+ categories.clear();
+ solver.clear();
+ solution.clear();
+ basepkg = packageversion();
+ dependencyOrderedPackages.clear();
+}
+
void
packagedb::read ()
{
diff --git a/package_db.h b/package_db.h
index d7127a6..a26c387 100644
--- a/package_db.h
+++ b/package_db.h
@@ -64,6 +64,7 @@ class packagedb
{
public:
packagedb ();
+ void init();
void read();
void makeBase();
/* 0 on success */
--
2.15.0