From de95eb255b0fbf5b4ec0e60d95967e7cac13637c Mon Sep 17 00:00:00 2001 From: Daniel Hartwig Date: Fri, 2 Mar 2012 19:57:34 +0800 Subject: Move code for reading Top Sections to apt.cc --- src/generic/apt/apt.cc | 24 ++++++++++++++++++++++++ src/generic/apt/apt.h | 8 ++++++++ src/pkg_grouppolicy.cc | 10 ++-------- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/generic/apt/apt.cc b/src/generic/apt/apt.cc index c535dcfe..e1167e93 100644 --- a/src/generic/apt/apt.cc +++ b/src/generic/apt/apt.cc @@ -1309,5 +1309,29 @@ namespace aptitude return true; } + + const std::vector get_top_sections(const bool cached) + { + static std::vector top_sections; + + if(top_sections.empty() == false) + { + if(cached == true) + return top_sections; + else + top_sections.clear(); + } + + top_sections = aptcfg->FindVector(PACKAGE "::Sections::Top-Sections"); + if(top_sections.empty() == true) + { + top_sections.push_back("main"); + top_sections.push_back("contrib"); + top_sections.push_back("non-free"); + top_sections.push_back("non-US"); + } + + return top_sections; + } } } diff --git a/src/generic/apt/apt.h b/src/generic/apt/apt.h index fc6fb64a..a052fb7e 100644 --- a/src/generic/apt/apt.h +++ b/src/generic/apt/apt.h @@ -29,6 +29,7 @@ #include #include +#include /** \brief Central repository for apt structures * @@ -436,6 +437,13 @@ namespace aptitude * version aren't considered; should they be? */ bool is_full_replacement(const pkgCache::DepIterator &dep); + + /** \return an ordered vector of the Top Sections + * + * From the configuration item Aptitude::Sections::Top-Sections + * or a builtin list of defaults. + */ + const std::vector get_top_sections(const bool cached=true); } } diff --git a/src/pkg_grouppolicy.cc b/src/pkg_grouppolicy.cc index 50343a4d..fa69c9ae 100644 --- a/src/pkg_grouppolicy.cc +++ b/src/pkg_grouppolicy.cc @@ -360,14 +360,8 @@ void pkg_grouppolicy_section::add_package(const pkgCache::PkgIterator &pkg, int order = -1; { // get an ordered list of top-sections - vector topSections = aptcfg->FindVector(PACKAGE "::Sections::Top-Sections"); - if (topSections.empty()) { - // provide some sensible defaults - topSections.push_back("main"); - topSections.push_back("contrib"); - topSections.push_back("non-free"); - topSections.push_back("non-US"); - } + const vector topSections = aptitude::apt::get_top_sections(); + // get the order of the top-section (the lower the number, // the higher the priority) for (size_t i = 0; i < topSections.size(); ++i) { -- cgit v1.2.3