Skip to content

Commit

Permalink
changed loading order of packages from undefined to sorted by name
Browse files Browse the repository at this point in the history
  • Loading branch information
turleypol committed Oct 12, 2019
1 parent 6950962 commit 17981ff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
20 changes: 11 additions & 9 deletions pol-core/plib/pkg.cpp
Expand Up @@ -7,6 +7,7 @@
#include "pkg.h" #include "pkg.h"


#include "pol_global_config.h" #include "pol_global_config.h"
#include <algorithm>
#include <stdlib.h> #include <stdlib.h>


#include "../clib/cfgelem.h" #include "../clib/cfgelem.h"
Expand Down Expand Up @@ -45,21 +46,18 @@ Package* find_package( const std::string& pkgname )


void remove_package( Package* pkg ) void remove_package( Package* pkg )
{ {
auto last = std::remove_if( systemstate.packages.begin(), systemstate.packages.end(), auto last = std::remove( systemstate.packages.begin(), systemstate.packages.end(), pkg );
std::bind2nd( std::equal_to<Package*>(), pkg ) );
systemstate.packages.erase( last, systemstate.packages.end() ); systemstate.packages.erase( last, systemstate.packages.end() );


// TODO: Check this loop. It looks odd.
// Should the loop stop after removing the package?
// Is it possible to have more than one name for the same package?

auto itr = systemstate.packages_byname.begin(); auto itr = systemstate.packages_byname.begin();
while ( itr != systemstate.packages_byname.end() ) while ( itr != systemstate.packages_byname.end() )
{ {
auto tempitr = itr; if ( itr->second == pkg )
{
systemstate.packages_byname.erase( itr );
break;
}
++itr; ++itr;
if ( ( *tempitr ).second == pkg )
systemstate.packages_byname.erase( tempitr );
} }
} }


Expand Down Expand Up @@ -406,6 +404,10 @@ void load_packages( bool quiet )
replace_packages(); replace_packages();


check_package_deps(); check_package_deps();
// sort pkg vector by name, so e.g. startup order is in a defined and maybe also expected order.
std::sort(
systemstate.packages.begin(), systemstate.packages.end(),
[]( const Package* pkg1, const Package* pkg2 ) { return pkg1->name() < pkg2->name(); } );
} }


bool pkgdef_split( const std::string& spec, const Package* inpkg, const Package** outpkg, bool pkgdef_split( const std::string& spec, const Package* inpkg, const Package** outpkg,
Expand Down
1 change: 1 addition & 0 deletions pol-core/plib/systemstate.h
Expand Up @@ -32,6 +32,7 @@ class SystemState
SystemState& operator=( const SystemState& ) = delete; SystemState& operator=( const SystemState& ) = delete;
void deinitialize(); void deinitialize();


// TODO: why two containers? keep the map when often name is searched?
Packages packages; Packages packages;
PackagesByName packages_byname; PackagesByName packages_byname;


Expand Down

0 comments on commit 17981ff

Please sign in to comment.