Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / zypp / RepoInfo.cc
index 679a432..a91e9f5 100644 (file)
@@ -48,6 +48,7 @@ namespace zypp
       , _pkgGpgCheck( indeterminate )
       , _validRepoSignature( indeterminate )
       ,        keeppackages(indeterminate)
+      , _mirrorListForceMetalink(false)
       , type(repo::RepoType::NONE_e)
       , emptybaseurls(false)
     {}
@@ -57,6 +58,7 @@ namespace zypp
 
   public:
     static const unsigned defaultPriority = 99;
+    static const unsigned noPriority = unsigned(-1);
 
     void setProbedType( const repo::RepoType & t ) const
     {
@@ -79,7 +81,7 @@ namespace zypp
       {
         emptybaseurls = true;
         DBG << "MetadataPath: " << metadatapath << endl;
-       repo::RepoMirrorList rmurls( mlurl, metadatapath );
+       repo::RepoMirrorList rmurls( mlurl, metadatapath, _mirrorListForceMetalink );
        _baseUrls.raw().insert( _baseUrls.raw().end(), rmurls.getUrls().begin(), rmurls.getUrls().end() );
       }
       return _baseUrls;
@@ -98,15 +100,19 @@ namespace zypp
     RepoVariablesReplacedUrlList & gpgKeyUrls()
     { return _gpgKeyUrls; }
 
+
+    const std::set<std::string> & contentKeywords() const
+    { hasContent()/*init if not yet done*/; return _keywords.second; }
+
     void addContent( const std::string & keyword_r )
-    { _keywords.insert( keyword_r ); }
+    { _keywords.second.insert( keyword_r ); if ( ! hasContent() ) _keywords.first = true; }
 
-    bool hasContent( const std::string & keyword_r ) const
+    bool hasContent() const
     {
-      if ( _keywords.empty() && ! metadatapath.empty() )
+      if ( !_keywords.first && ! metadatapath.empty() )
       {
        // HACK directly check master index file until RepoManager offers
-       // some content probing ans zypepr uses it.
+       // some content probing and zypper uses it.
        /////////////////////////////////////////////////////////////////
        MIL << "Empty keywords...." << metadatapath << endl;
        Pathname master;
@@ -116,10 +122,10 @@ namespace zypp
          xml::Reader reader( master );
          while ( reader.seekToNode( 2, "content" ) )
          {
-           _keywords.insert( reader.nodeText().asString() );
+           _keywords.second.insert( reader.nodeText().asString() );
            reader.seekToEndNode( 2, "content" );
          }
-         _keywords.insert( "" );       // valid content in _keywords even if empty
+         _keywords.first = true;       // valid content in _keywords even if empty
        }
        else if ( PathInfo( (master=metadatapath/"/content") ).isFile() )
        {
@@ -133,19 +139,22 @@ namespace zypp
                                if ( str::split( line_r, std::back_inserter(words) ) > 1
                                  && words[0].length() == 12 /*"REPOKEYWORDS"*/ )
                                {
-                                 this->_keywords.insert( ++words.begin(), words.end() );
+                                 this->_keywords.second.insert( ++words.begin(), words.end() );
                                }
                                return true; // mult. occurrances are ok.
                              }
                              return( ! str::startsWith( line_r, "META " ) );   // no need to parse into META section.
                            } );
-         _keywords.insert( "" );
+         _keywords.first = true;       // valid content in _keywords even if empty
        }
        /////////////////////////////////////////////////////////////////
       }
-      return( _keywords.find( keyword_r ) != _keywords.end() );
+      return _keywords.first;
     }
 
+    bool hasContent( const std::string & keyword_r ) const
+    { return( hasContent() && _keywords.second.find( keyword_r ) != _keywords.second.end() ); }
+
     /** Signature check result needs to be stored/retrieved from _metadatapath.
      * Don't call them from outside validRepoSignature/setValidRepoSignature
      */
@@ -213,6 +222,7 @@ namespace zypp
   public:
     TriBool keeppackages;
     RepoVariablesReplacedUrl _mirrorListUrl;
+    bool                     _mirrorListForceMetalink;
     repo::RepoType type;
     Pathname path;
     std::string service;
@@ -225,7 +235,7 @@ namespace zypp
 
   private:
     mutable RepoVariablesReplacedUrlList _baseUrls;
-    mutable std::set<std::string> _keywords;
+    mutable std::pair<FalseBool, std::set<std::string> > _keywords;
 
     RepoVariablesReplacedUrlList _gpgKeyUrls;
 
@@ -263,6 +273,9 @@ namespace zypp
   unsigned RepoInfo::defaultPriority()
   { return Impl::defaultPriority; }
 
+  unsigned RepoInfo::noPriority()
+  { return Impl::noPriority; }
+
   void RepoInfo::setPriority( unsigned newval_r )
   { _pimpl->priority = newval_r ? newval_r : Impl::defaultPriority; }
 
@@ -320,7 +333,10 @@ namespace zypp
 
 
   void RepoInfo::setMirrorListUrl( const Url & url_r ) // Raw
-  { _pimpl->_mirrorListUrl.raw() = url_r; }
+  { _pimpl->_mirrorListUrl.raw() = url_r; _pimpl->_mirrorListForceMetalink = false; }
+
+  void  RepoInfo::setMetalinkUrl( const Url & url_r )  // Raw
+  { _pimpl->_mirrorListUrl.raw() = url_r; _pimpl->_mirrorListForceMetalink = true; }
 
   void RepoInfo::setGpgKeyUrls( url_set urls )
   { _pimpl->gpgKeyUrls().raw().swap( urls ); }
@@ -442,10 +458,15 @@ namespace zypp
   bool RepoInfo::baseUrlSet() const
   { return _pimpl->baseurl2dump(); }
 
+  const std::set<std::string> & RepoInfo::contentKeywords() const
+  { return _pimpl->contentKeywords(); }
 
   void RepoInfo::addContent( const std::string & keyword_r )
   { _pimpl->addContent( keyword_r ); }
 
+  bool RepoInfo::hasContent() const
+  { return _pimpl->hasContent(); }
+
   bool RepoInfo::hasContent( const std::string & keyword_r ) const
   { return _pimpl->hasContent( keyword_r ); }
 
@@ -495,8 +516,7 @@ namespace zypp
       return std::string();
 
     Locale getLang( Locale::bestMatch( avlocales, lang_r ) );
-    if ( getLang == Locale::noCode
-         && avlocales.find( Locale::noCode ) == avlocales.end() )
+    if ( !getLang && avlocales.find( Locale::noCode ) == avlocales.end() )
     {
       WAR << "License.tar.gz contains no fallback text! " << *this << endl;
       // Using the fist locale instead of returning no text at all.
@@ -507,9 +527,8 @@ namespace zypp
 
     // now extract the license file.
     static const std::string licenseFileFallback( "license.txt" );
-    std::string licenseFile( getLang == Locale::noCode
-                             ? licenseFileFallback
-                             : str::form( "license.%s.txt", getLang.code().c_str() ) );
+    std::string licenseFile( !getLang ? licenseFileFallback
+                                     : str::form( "license.%s.txt", getLang.c_str() ) );
 
     ExternalProgram::Arguments cmd;
     cmd.push_back( "tar" );
@@ -580,7 +599,7 @@ namespace zypp
        str << tag_r << value_r << std::endl;
     });
 
-    strif( "- mirrorlist  : ", rawMirrorListUrl().asString() );
+    strif( (_pimpl->_mirrorListForceMetalink ? "- metalink    : " : "- mirrorlist  : "), rawMirrorListUrl().asString() );
     strif( "- path        : ", path().asString() );
     str << "- type        : " << type() << std::endl;
     str << "- priority    : " << priority() << std::endl;
@@ -629,7 +648,7 @@ namespace zypp
       str << "path="<< path() << endl;
 
     if ( ! (rawMirrorListUrl().asString().empty()) )
-      str << "mirrorlist=" << rawMirrorListUrl() << endl;
+      str << (_pimpl->_mirrorListForceMetalink ? "metalink=" : "mirrorlist=") << rawMirrorListUrl() << endl;
 
     str << "type=" << type().asString() << endl;
 
@@ -683,7 +702,7 @@ namespace zypp
     if (!(tmpstr = gpgKeyUrl().asString()).empty())
       str << " gpgkey=\"" << escape(tmpstr) << "\"";
     if (!(tmpstr = mirrorListUrl().asString()).empty())
-      str << " mirrorlist=\"" << escape(tmpstr) << "\"";
+      str << (_pimpl->_mirrorListForceMetalink ? " metalink=\"" : " mirrorlist=\"") << escape(tmpstr) << "\"";
     str << ">" << endl;
 
     if ( _pimpl->baseurl2dump() )