Author: mlandres Date: Wed Oct 22 14:35:41 2008 New Revision: 11447 URL: http://svn.opensuse.org/viewcvs/zypp?rev=11447&view=rev Log: - For retrieving a product license fall back to license.tar.gz. (bnc #372386) Modified: trunk/libzypp/zypp/RepoInfo.cc trunk/libzypp/zypp/RepoInfo.h trunk/libzypp/zypp/ResObject.cc Modified: trunk/libzypp/zypp/RepoInfo.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/RepoInfo.cc?rev=11447&r1=11446&r2=11447&view=diff ============================================================================== --- trunk/libzypp/zypp/RepoInfo.cc (original) +++ trunk/libzypp/zypp/RepoInfo.cc Wed Oct 22 14:35:41 2008 @@ -13,11 +13,12 @@ #include "zypp/base/Logger.h" #include "zypp/base/DefaultIntegral.h" -#include "zypp/media/MediaAccess.h" #include "zypp/parser/xml/XmlEscape.h" #include "zypp/RepoInfo.h" #include "zypp/repo/RepoInfoBaseImpl.h" +#include "zypp/ExternalProgram.h" +#include "zypp/media/MediaAccess.h" using namespace std; using zypp::xml::escape; @@ -57,6 +58,11 @@ } public: + Pathname licenseTgz() const + { return metadatapath.empty() ? Pathname() : metadatapath / "license.tar.gz"; } + + + public: TriBool gpgcheck; TriBool keeppackages; Url gpgkey_url; @@ -265,16 +271,93 @@ return (bool) _pimpl->keeppackages; } + /////////////////////////////////////////////////////////////////// bool RepoInfo::hasLicense() const - { return false; } + { + Pathname licenseTgz( _pimpl->licenseTgz() ); + INT << alias() << ": " << PathInfo( licenseTgz ) << endl; + return ! licenseTgz.empty() && PathInfo(licenseTgz).isFile(); + } - ManagedFile RepoInfo::getLicense( const Locale & lang_r ) - { return ManagedFile(); } + std::string RepoInfo::getLicense( const Locale & lang_r ) + { + LocaleSet avlocales( getLicenseLocales() ); + if ( avlocales.empty() ) + return std::string(); + + Locale getLang( Locale::bestMatch( avlocales, lang_r ) ); + if ( getLang == Locale::noCode + && 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. + // So the user might recognize that there is a license, even if he + // can't read it. + getLang = *avlocales.begin(); + } + + // 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() ) ); + + ExternalProgram::Arguments cmd; + cmd.push_back( "tar" ); + cmd.push_back( "-x" ); + cmd.push_back( "-z" ); + cmd.push_back( "-O" ); + cmd.push_back( "-f" ); + cmd.push_back( _pimpl->licenseTgz().asString() ); // if it not exists, avlocales was empty. + cmd.push_back( licenseFile ); + + std::string ret; + ExternalProgram prog( cmd, ExternalProgram::Discard_Stderr ); + for ( std::string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() ) + { + ret += output; + } + prog.close(); + return ret; + } LocaleSet RepoInfo::getLicenseLocales() const - { return LocaleSet(); } + { + Pathname licenseTgz( _pimpl->licenseTgz() ); + if ( licenseTgz.empty() || ! PathInfo( licenseTgz ).isFile() ) + return LocaleSet(); + + ExternalProgram::Arguments cmd; + cmd.push_back( "tar" ); + cmd.push_back( "-t" ); + cmd.push_back( "-z" ); + cmd.push_back( "-f" ); + cmd.push_back( licenseTgz.asString() ); + + LocaleSet ret; + ExternalProgram prog( cmd, ExternalProgram::Stderr_To_Stdout ); + for ( std::string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() ) + { + static const C_Str license( "license." ); + static const C_Str dotTxt( ".txt\n" ); + if ( str::hasPrefix( output, license ) && str::hasSuffix( output, dotTxt ) ) + { + if ( output.size() <= license.size() + dotTxt.size() ) // license.txt + ret.insert( Locale() ); + else + ret.insert( Locale( std::string( output.c_str()+license.size(), output.size()- license.size() - dotTxt.size() ) ) ); + } + else + { + WAR << " " << output; + } + } + prog.close(); + return ret; + } + /////////////////////////////////////////////////////////////////// std::ostream & RepoInfo::dumpOn( std::ostream & str ) const { @@ -297,6 +380,9 @@ if (!targetDistribution().empty()) str << "- targetdistro: " << targetDistribution() << std::endl; + if (!metadataPath().empty()) + str << "- metadataPath: " << metadataPath() << std::endl; + return str; } Modified: trunk/libzypp/zypp/RepoInfo.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/RepoInfo.h?rev=11447&r1=11446&r2=11447&view=diff ============================================================================== --- trunk/libzypp/zypp/RepoInfo.h (original) +++ trunk/libzypp/zypp/RepoInfo.h Wed Oct 22 14:35:41 2008 @@ -20,7 +20,6 @@ #include "zypp/Url.h" #include "zypp/Locale.h" -#include "zypp/ManagedFile.h" #include "zypp/repo/RepoType.h" #include "zypp/repo/RepoVariables.h" @@ -301,8 +300,8 @@ /** Whether there is a license associated with the repo. */ bool hasLicense() const; - /** Return the best license file for the current (or a specified) locale. */ - ManagedFile getLicense( const Locale & lang_r = Locale() ); + /** Return the best license for the current (or a specified) locale. */ + std::string getLicense( const Locale & lang_r = Locale() ); /** Return the locales the license is available for. * \ref Locale::noCode is included in case of \c license.txt which does Modified: trunk/libzypp/zypp/ResObject.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/ResObject.cc?rev=11447&r1=11446&r2=11447&view=diff ============================================================================== --- trunk/libzypp/zypp/ResObject.cc (original) +++ trunk/libzypp/zypp/ResObject.cc Wed Oct 22 14:35:41 2008 @@ -68,7 +68,12 @@ { return lookupStrAttribute( sat::SolvAttr::delnotify, lang_r ); } std::string ResObject::licenseToConfirm( const Locale & lang_r ) const - { return lookupStrAttribute( sat::SolvAttr::eula, lang_r ); } + { + std::string ret = lookupStrAttribute( sat::SolvAttr::eula, lang_r ); + if ( ret.empty() && isKind<Product>() ) + return repoInfo().getLicense( lang_r ); + return ret; + } std::string ResObject::distribution() const { return lookupStrAttribute( sat::SolvAttr::distribution ); } -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org