LibsolvSolver: Fix the lazy re-/initialization
* _Init() was a bit too enthusiastic, throwing really everything away. So, after calling it at the beginning of _AddRepositories() there wouldn't be any repositories anymore. * Rename _Init() to _InitPool() to make its purpose clearer. * Pull a _CleanupPool() out of _Cleanup() that only deletes the pool and anything depending on it. * RepositoryInfo::HasChanged(): Always consider changed when there's no libsolv repo yet.
This commit is contained in:
@@ -62,7 +62,7 @@ struct LibsolvSolver::RepositoryInfo {
|
|||||||
:
|
:
|
||||||
fRepository(repository),
|
fRepository(repository),
|
||||||
fSolvRepo(NULL),
|
fSolvRepo(NULL),
|
||||||
fChangeCount(repository->ChangeCount() - 1)
|
fChangeCount(repository->ChangeCount())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ struct LibsolvSolver::RepositoryInfo {
|
|||||||
|
|
||||||
bool HasChanged() const
|
bool HasChanged() const
|
||||||
{
|
{
|
||||||
return fChangeCount != fRepository->ChangeCount();
|
return fChangeCount != fRepository->ChangeCount() || fSolvRepo == NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetUnchanged()
|
void SetUnchanged()
|
||||||
@@ -162,6 +162,8 @@ LibsolvSolver::~LibsolvSolver()
|
|||||||
status_t
|
status_t
|
||||||
LibsolvSolver::Init()
|
LibsolvSolver::Init()
|
||||||
{
|
{
|
||||||
|
_Cleanup();
|
||||||
|
|
||||||
// We do all initialization lazily.
|
// We do all initialization lazily.
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -370,9 +372,9 @@ LibsolvSolver::GetResult(BSolverResult& _result)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
LibsolvSolver::_Init()
|
LibsolvSolver::_InitPool()
|
||||||
{
|
{
|
||||||
_Cleanup();
|
_CleanupPool();
|
||||||
|
|
||||||
fPool = pool_create();
|
fPool = pool_create();
|
||||||
|
|
||||||
@@ -403,12 +405,28 @@ LibsolvSolver::_Init()
|
|||||||
void
|
void
|
||||||
LibsolvSolver::_Cleanup()
|
LibsolvSolver::_Cleanup()
|
||||||
{
|
{
|
||||||
_CleanupSolver();
|
_CleanupPool();
|
||||||
|
|
||||||
fSolvablePackages.clear();
|
|
||||||
fInstalledRepository = NULL;
|
fInstalledRepository = NULL;
|
||||||
fRepositoryInfos.MakeEmpty();
|
fRepositoryInfos.MakeEmpty();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
LibsolvSolver::_CleanupPool()
|
||||||
|
{
|
||||||
|
// clean up solver data
|
||||||
|
_CleanupSolver();
|
||||||
|
|
||||||
|
// clean up our data structures that depend on/refer to libsolv pool data
|
||||||
|
fSolvablePackages.clear();
|
||||||
|
|
||||||
|
int32 repositoryCount = fRepositoryInfos.CountItems();
|
||||||
|
for (int32 i = 0; i < repositoryCount; i++)
|
||||||
|
fRepositoryInfos.ItemAt(i)->SetSolvRepo(NULL);
|
||||||
|
|
||||||
|
// delete the pool
|
||||||
if (fPool != NULL) {
|
if (fPool != NULL) {
|
||||||
pool_free(fPool);
|
pool_free(fPool);
|
||||||
fPool = NULL;
|
fPool = NULL;
|
||||||
@@ -449,7 +467,7 @@ LibsolvSolver::_AddRepositories()
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
// something has changed -- re-create the pool
|
// something has changed -- re-create the pool
|
||||||
status_t error = _Init();
|
status_t error = _InitPool();
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
|
|||||||
@@ -55,8 +55,9 @@ private:
|
|||||||
typedef std::map<Solvable*, BSolverPackage*> SolvableMap;
|
typedef std::map<Solvable*, BSolverPackage*> SolvableMap;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
status_t _Init();
|
status_t _InitPool();
|
||||||
void _Cleanup();
|
void _Cleanup();
|
||||||
|
void _CleanupPool();
|
||||||
void _CleanupSolver();
|
void _CleanupSolver();
|
||||||
|
|
||||||
bool _HaveRepositoriesChanged() const;
|
bool _HaveRepositoriesChanged() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user