From 1a57d31e525316f8a639a519c58f04f3b7b65128 Mon Sep 17 00:00:00 2001 From: Benjamin Zeller Date: Tue, 26 Jun 2018 15:59:09 +0200 Subject: [PATCH 1/2] Introduce Locale::hasFallback to check if a locale is a fallback for another --- zypp/Locale.cc | 9 +++++++++ zypp/Locale.h | 3 +++ 2 files changed, 12 insertions(+) diff --git a/zypp/Locale.cc b/zypp/Locale.cc index 53442e611a..804411c74f 100644 --- a/zypp/Locale.cc +++ b/zypp/Locale.cc @@ -205,6 +205,15 @@ namespace zypp std::string Locale::name() const { return CodeMaps::instance().name( _str ); } + bool Locale::hasFallback(const Locale &loc_r) const + { + for ( Locale fb = fallback(); fb; fb = fb.fallback() ) { + if ( fb == loc_r ) + return true; + } + return false; + } + Locale Locale::fallback() const { return CodeMaps::instance().fallback( _str ); } diff --git a/zypp/Locale.h b/zypp/Locale.h index 90b8ad543d..1db99866cc 100644 --- a/zypp/Locale.h +++ b/zypp/Locale.h @@ -91,6 +91,9 @@ namespace zypp /** Return the translated locale name. */ std::string name() const; + /** Checks if \a loc is in the fallback list for this locale */ + bool hasFallback (const Locale &loc_r ) const; + public: /** Return the fallback locale for this locale, if no fallback exists the empty Locale::noCode. * The usual fallback sequence is "language_COUNTRY" -> "language" -> Locale::enCode ("en") From 9e36ad91c741bf36eed0063f39eabf5f79e18727 Mon Sep 17 00:00:00 2001 From: Benjamin Zeller Date: Tue, 26 Jun 2018 15:59:27 +0200 Subject: [PATCH 2/2] Autoremove a locale only if its not the fallback for another enabled one --- zypp/sat/detail/PoolImpl.cc | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/zypp/sat/detail/PoolImpl.cc b/zypp/sat/detail/PoolImpl.cc index a5d042da4a..56d23752cb 100644 --- a/zypp/sat/detail/PoolImpl.cc +++ b/zypp/sat/detail/PoolImpl.cc @@ -505,8 +505,23 @@ namespace zypp // Add removed locales+fallback except they are still in current for ( Locale lang: localesTracker.removed() ) { - for ( ; lang && ! localeIds.current().count( IdString(lang) ); lang = lang.fallback() ) - { localeIds.removed().insert( IdString(lang) ); } + if ( lang && ! localeIds.current().count( IdString(lang) ) ) { + + //remove the requested one + localeIds.removed().insert( IdString(lang) ); + + //remove fallbacks + const auto &currLangs = localeIds.current(); + auto checkIsFallback = [&lang]( const IdString &currLoc_r ){ + return Locale(currLoc_r).hasFallback(lang); + }; + for ( lang = lang.fallback(); lang && ! localeIds.current().count( IdString(lang) ); lang = lang.fallback() ) { + //remove the language only if its not a fallback for any other + if ( std::none_of( currLangs.begin(), currLangs.end(), checkIsFallback ) ) + localeIds.removed().insert( IdString(lang) ); + } + } + } // Assert that TrackedLocaleIds::current is not empty.