16 #include <zypp/base/Gettext.h> 17 #include <zypp/base/LogTools.h> 19 #include <zypp/parser/xml/XmlEscape.h> 21 #include <zypp/ManagedFile.h> 26 #include <zypp/TriBool.h> 27 #include <zypp/Pathname.h> 30 #include <zypp/ExternalProgram.h> 32 #include <zypp/base/IOStream.h> 39 #include <zypp/TmpPath.h> 52 repo::RepoType probeCache(
const Pathname & path_r )
55 if ( PathInfo(path_r).isDir() )
57 if ( PathInfo(path_r/
"/repodata/repomd.xml").isFile() )
59 else if ( PathInfo(path_r/
"/content").isFile() )
61 else if ( PathInfo(path_r/
"/cookie").isFile() )
64 DBG <<
"Probed cached type " << ret <<
" at " << path_r << endl;
81 ,
_type(repo::RepoType::NONE_e)
117 std::string licenseStem(
"license" );
118 if ( !name_r.empty() )
121 licenseStem += name_r;
140 if (
_baseUrls.empty() && ! mlurl.asString().empty() )
194 [
this](
int num_r, std::string line_r )->
bool 198 std::vector<std::string> words;
199 if (
str::split( line_r, std::back_inserter(words) ) > 1
200 && words[0].length() == 12 )
202 this->
_keywords.second.insert( ++words.begin(), words.end() );
233 return indeterminate;
241 if (
PathInfo(gpgcheckFile).isExist() )
243 TriBool linkval( indeterminate );
266 static const Pathname truePath(
"true" );
267 static const Pathname falsePath(
"false" );
268 static const Pathname indeterminatePath(
"indeterminate" );
271 static const ssize_t bufsiz = 63;
272 static char buf[bufsiz+1];
274 buf[ret == -1 ? 0 : ret] =
'\0';
279 if ( linkval == truePath )
281 else if ( linkval == falsePath )
283 else if ( linkval == indeterminatePath )
284 ret_r = indeterminate;
358 mutable std::pair<FalseBool, std::set<std::string> >
_keywords;
362 friend Impl * rwcowClone<Impl>(
const Impl * rhs );
365 {
return new Impl( *
this ); }
372 return str <<
"RepoInfo::Impl";
384 : _pimpl( new
Impl() )
460 {
if ( ! sameTriboolState( lhs, rhs ) ) { lhs = rhs;
return true; }
return false; }
464 bool changed =
false;
465 if ( changeGpgCheckTo( ogpg[0], g ) ) changed =
true;
466 if ( changeGpgCheckTo( ogpg[1], r ) ) changed =
true;
467 if ( changeGpgCheckTo( ogpg[2], p ) ) changed =
true;
477 bool changed =
false;
481 changed = changeGpgCheckTo( ogpg,
true, indeterminate, indeterminate );
484 changed = changeGpgCheckTo( ogpg,
true,
true,
true );
487 changed = changeGpgCheckTo( ogpg,
true,
false,
false );
490 changed = changeGpgCheckTo( ogpg,
true,
false, indeterminate );
493 changed = changeGpgCheckTo( ogpg,
true, indeterminate,
false );
496 changed = changeGpgCheckTo( ogpg, indeterminate, indeterminate, indeterminate );
499 changed = changeGpgCheckTo( ogpg,
false, indeterminate, indeterminate );
537 if ( keyID_r.empty() )
540 MIL <<
"Check for " << keyID_r <<
" at " << targetDirectory_r << endl;
541 std::string keyIDStr( keyID_r.size() > 8 ? keyID_r.substr( keyID_r.size()-8 ) : keyID_r );
550 [&tempKeyRing](
const Pathname & dir_r,
const std::string & str_r ){
560 tempKeyRing.multiKeyImport(dir_r/str_r,
true);
564 ERR <<
"Error importing cached key from file '"<<dir_r/str_r<<
"'."<<endl;
571 if ( !tempKeyRing.isKeyTrusted(keyID_r) ) {
588 tempKeyRing.multiKeyImport(f,
true);
590 }
catch (
const std::exception & e ) {
593 MIL <<
"Key import from url:'"<<
url<<
"' failed." << endl;
607 for (
const auto & key: tempKeyRing.trustedPublicKeyData()) {
608 MIL <<
"KEY ID in KEYRING: " << key.id() << endl;
612 std::ofstream fout( keyFile.
c_str(), std::ios_base::out | std::ios_base::trunc );
617 tempKeyRing.dumpTrustedPublicKey( key.id(), fout );
621 if ( !tempKeyRing.isKeyTrusted(keyID_r) ) {
625 PublicKeyData keyData( tempKeyRing.trustedPublicKeyData( keyID_r ) );
627 ERR <<
"Error when exporting key from temporary keychain." << endl;
775 if ( licenseTgz.empty() )
779 cmd.push_back(
"tar" );
780 cmd.push_back(
"-t" );
781 cmd.push_back(
"-z" );
782 cmd.push_back(
"-f" );
783 cmd.push_back( licenseTgz.asString() );
787 static const std::string noAcceptanceFile =
"no-acceptance-needed\n";
790 if ( output == noAcceptanceFile )
796 MIL <<
"License(" << name_r <<
") in " <<
name() <<
" has to be accepted: " << (accept?
"true":
"false" ) << endl;
805 {
return getLicense( std::string(), lang_r ); }
810 if ( avlocales.empty() )
811 return std::string();
814 if ( !getLang && avlocales.find(
Locale::noCode ) == avlocales.end() )
816 WAR <<
"License(" << name_r <<
") in " <<
name() <<
" contains no fallback text!" << endl;
820 getLang = *avlocales.begin();
824 static const std::string licenseFileFallback(
"license.txt" );
825 std::string licenseFile( !getLang ? licenseFileFallback
829 cmd.push_back(
"tar" );
830 cmd.push_back(
"-x" );
831 cmd.push_back(
"-z" );
832 cmd.push_back(
"-O" );
833 cmd.push_back(
"-f" );
835 cmd.push_back( licenseFile );
854 if ( licenseTgz.empty() )
858 cmd.push_back(
"tar" );
859 cmd.push_back(
"-t" );
860 cmd.push_back(
"-z" );
861 cmd.push_back(
"-f" );
862 cmd.push_back( licenseTgz.asString() );
868 static const C_Str license(
"license." );
869 static const C_Str dotTxt(
".txt\n" );
872 if ( output.size() <= license.
size() + dotTxt.
size() )
875 ret.insert(
Locale( std::string( output.c_str()+license.
size(), output.size()- license.
size() - dotTxt.
size() ) ) );
891 str <<
"- url : " <<
url << std::endl;
896 auto strif( [&] (
const std::string & tag_r,
const std::string & value_r ) {
897 if ( ! value_r.empty() )
898 str << tag_r << value_r << std::endl;
903 str <<
"- type : " <<
type() << std::endl;
907 #define OUTS(T,B) ( indeterminate(T) ? (std::string("D(")+(B?"Y":"N")+")") : ((bool)T?"Y":"N") ) 917 str <<
"- gpgkey : " <<
url << std::endl;
923 strif(
"- service : ",
service() );
934 RepoInfoBase::dumpAsIniOn(
str);
943 if ( indent.empty() ) indent =
" ";
948 str <<
"path="<<
path() << endl;
969 std::string indent(
"gpgkey=");
972 str << indent <<
url << endl;
973 if ( indent[0] !=
' ' )
997 <<
" priority=\"" <<
priority() <<
"\"" 998 <<
" enabled=\"" <<
enabled() <<
"\"" 1000 <<
" gpgcheck=\"" <<
gpgCheck() <<
"\"" 1011 str <<
" gpgkey=\"" <<
escape(tmpstr) <<
"\"";
1019 str <<
"<url>" <<
escape((*it).asString()) <<
"</url>" << endl;
1022 str <<
"</repo>" << endl;
1036 #define OUTS( V ) case RepoInfo::V: return str << #V; break 1037 OUTS( GpgCheck::On );
1038 OUTS( GpgCheck::Strict );
1039 OUTS( GpgCheck::AllowUnsigned );
1040 OUTS( GpgCheck::AllowUnsignedRepo );
1041 OUTS( GpgCheck::AllowUnsignedPackage );
1043 OUTS( GpgCheck::Off );
1044 OUTS( GpgCheck::indeterminate );
1047 return str <<
"GpgCheck::UNKNOWN";
static const Locale noCode
Empty code.
Pathname filepath() const
File where this repo was read from.
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
Pathname path() const
Repository path.
unsigned priority() const
Repository priority for solver.
bool hasLicense() const
Whether there is a license associated with the repo.
url_set gpgKeyUrls() const
The list of gpgkey URLs defined for this repo.
void setGpgKeyUrl(const Url &gpgkey)
(leagcy API) Set the gpgkey URL defined for this repo
static unsigned defaultPriority()
The default priority (99).
Url rawGpgKeyUrl() const
(leagcy API) The 1st raw gpgkey URL defined for this repo (no variables replaced) ...
Url rawUrl() const
Pars pro toto: The first repository raw url (no variables replaced)
TriBool rawPkgGpgCheck() const
const std::set< std::string > & contentKeywords() const
Content keywords defined.
void packagesPath(Pathname new_r)
std::string asString(const DefaultIntegral< Tp, TInitial > &obj)
virtual std::ostream & dumpOn(std::ostream &str) const
Write a human-readable representation of this RepoInfo object into the str stream.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
bool _mirrorListForceMetalink
static ZConfig & instance()
Singleton ctor.
std::string service() const
Gets name of the service to which this repository belongs or empty string if it has been added manual...
void setProbedType(const repo::RepoType &t) const
This allows to adjust the RepoType lazy, from NONE to some probed value, even for const objects...
void setPriority(unsigned newval_r)
Set repository priority for solver.
std::ostream & operator<<(std::ostream &str, const InputStream &obj)
int readlink(const Pathname &symlink_r, Pathname &target_r)
Like 'readlink'.
void rawGpgCheck(TriBool val_r)
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Pathname provideKey(const std::string &keyID_r, const Pathname &targetDirectory_r) const
downloads all configured gpg keys into the defined directory
String matching (STRING|SUBSTRING|GLOB|REGEX).
void setMirrorListUrl(const Url &url)
Set mirror list url.
Class representing one GPG Public Keys data.
int dirForEach(const Pathname &dir_r, const StrMatcher &matcher_r, function< bool(const Pathname &, const char *const)> fnc_r)
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
const char * c_str() const
String representation.
std::ostream & operator<<(std::ostream &str, const RepoInfo::Impl &obj)
bool pkgGpgCheckIsMandatory() const
Mandatory check (pkgGpgCheck is not off) must ask to confirm using unsigned packages.
url_set rawGpgKeyUrls() const
The list of raw gpgkey URLs defined for this repo (no variables replaced)
String related utilities and Regular expression matching.
What is known about a repository.
void setGpgCheck(TriBool value_r)
Set the value for gpgCheck (or indeterminate to use the default).
TriBool _rawPkgGpgCheck
need to check pkg sign.: Y/N/(ZConf(Y/N/gpgCheck))
std::string asUserString() const
User string: label (alias or name)
std::string receiveLine()
Read one line from the input stream.
Request the standard behavior (as defined in zypp.conf or 'Job')
void setBaseUrl(const Url &url)
Clears current base URL list and adds url.
bool usesAutoMethadataPaths() const
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
bool enabled() const
If enabled is false, then this repository must be ignored as if does not exists, except when checking...
void internalSetValidRepoSignature(TriBool value_r)
Url gpgKeyUrl() const
(leagcy API) The 1st gpgkey URL defined for this repo
TriBool internalValidRepoSignature() const
Signature check result needs to be stored/retrieved from _metadataPath.
base::ValueTransform< Url, repo::RepoVariablesUrlReplacer > RepoVariablesReplacedUrl
bool repoGpgCheck() const
Whether the signature of repo metadata should be checked for this repo.
bool triBoolFromPath(const Pathname &path_r, TriBool &ret_r) const
const_iterator begin() const
Iterator pointing to the first result.
bool usesAutoMethadataPaths() const
Whether metadataPath uses AUTO% setup.
void setValidRepoSignature(TriBool value_r)
Set the value for validRepoSignature (or indeterminate if unsigned).
std::vector< std::string > Arguments
urls_const_iterator baseUrlsBegin() const
iterator that points at begin of repository urls
bool seekToNode(int depth_r, const std::string &name_r)
static const ValueType month
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
void setMirrorListUrls(url_set urls)
Like setMirrorListUrl but take an url_set.
bool baseUrlsEmpty() const
whether repository urls are available
transform_iterator< repo::RepoVariablesUrlReplacer, url_set::const_iterator > urls_const_iterator
const std::string & asString() const
RepoVariablesReplacedUrlList _baseUrls
static Locale bestMatch(const LocaleSet &avLocales_r, Locale requested_r=Locale())
Return the best match for Locale requested_r within the available avLocales_r.
Url url() const
Pars pro toto: The first repository url.
Url mirrorListUrl() const
Url of a file which contains a list of repository urls.
bool empty() const
Test for an empty path.
bool keepPackages() const
Whether packages downloaded from this repository will be kept in local cache.
unsigned split(const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=" \, const Trim trim_r=NO_TRIM)
Split line_r into words.
std::string asString() const
Returns a default string representation of the Url object.
bool gpgKeyUrlsEmpty() const
Whether gpgkey URLs are defined.
std::string escape(const C_Str &str_r, const char sep_r)
Escape desired character c using a backslash.
GpgCheck
Some predefined settings.
TriBool pkgGpgCheck() const
Check rpm package signatures (indeterminate - according to gpgcheck)
Provide a new empty temporary directory and recursively delete it when no longer needed.
bool pkgGpgCheck() const
Whether the signature of rpm packages should be checked for this repo.
Pathname packagesPath() const
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
int unlink(const Pathname &path)
Like 'unlink'.
bool repoGpgCheckIsMandatory() const
Mandatory check (repoGpgCheck is on) must ask to confirm using unsigned repos.
RepoVariablesReplacedUrlList & baseUrls()
void setRepoGpgCheck(TriBool value_r)
Set the value for repoGpgCheck (or indeterminate to use the default).
const std::string & asString() const
String representation.
TriBool triBoolFromPath(const Pathname &path_r) const
std::string alias() const
unique identifier for this source.
void addContent(const std::string &keyword_r)
bool gpgCheck() const
Turn signature checking on/off (on)
Convenience char* constructible from std::string and char*, it maps (char*)0 to an empty string...
int forEachLine(std::istream &str_r, function< bool(int, std::string)> consume_r)
Simple lineparser: Call functor consume_r for each line.
Url rawMirrorListUrl() const
The raw mirrorListUrl (no variables replaced).
void setPath(const Pathname &path)
set the product path.
TriBool validRepoSignature() const
Whether the repo metadata are signed and successfully validated or indeterminate if unsigned...
Pathname dirname() const
Return all but the last component od this path.
LocaleSet getLicenseLocales() const
Return the locales the license is available for.
void setService(const std::string &name)
sets service which added this repository
void setMetadataPath(const Pathname &path)
Set the path where the local metadata is stored.
bool baseUrlSet() const
Whether there are manualy configured repository urls.
RepoVariablesReplacedUrlList & gpgKeyUrls()
bool startsWith(const C_Str &str_r, const C_Str &prefix_r)
alias for hasPrefix
void getRawGpgChecks(TriBool &g_r, TriBool &r_r, TriBool &p_r) const
Raw values for RepoManager.
void setType(const repo::RepoType &t)
set the repository type
TriBool repoGpgCheck() const
Check repo matadata signatures (indeterminate - according to gpgcheck)
bool gpgCheck() const
Whether default signature checking should be performed.
TriBool _rawGpgCheck
default gpgcheck behavior: Y/N/ZConf
TriBool _validRepoSignature
have signed and valid repo metadata
bool hasContent() const
Check for content keywords.
std::pair< FalseBool, std::set< std::string > > _keywords
void setKeepPackages(bool keep)
Set if packaqes downloaded from this repository will be kept in local cache.
std::string getLicense(const Locale &lang_r=Locale()) const
Return the best license for the current (or a specified) locale.
bool baseurl2dump() const
bool empty() const
Whether matches were found.
std::string asString(const Url &url_r)
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
bool seekToEndNode(int depth_r, const std::string &name_r)
const RepoVariablesReplacedUrlList & baseUrls() const
int symlink(const Pathname &oldpath, const Pathname &newpath)
Like 'symlink'.
void addBaseUrl(const Url &url)
Add a base url.
TriBool cfgPkgGpgCheck() const
TriBool _rawRepoGpgCheck
need to check repo sign.: Y/N/(ZConf(Y/N/gpgCheck))
Find pathnames matching a pattern.
Pathname metadataPath() const
Path where this repo metadata was read from.
static const RepoType NONE
static const unsigned noPriority
base::ContainerTransform< std::list< Url >, repo::RepoVariablesUrlReplacer > RepoVariablesReplacedUrlList
repo::RepoType type() const
int add(const Pathname &pattern_r, Flags flags_r=Flags())
Add pathnames matching pattern_r to the current result.
void setPackagesPath(const Pathname &path)
set the path where the local packages are stored
virtual std::ostream & dumpAsXmlOn(std::ostream &str, const std::string &content="") const
Write an XML representation of this RepoInfo object.
'Language[_Country]' codes.
int close()
Wait for the progamm to complete.
void setMetalinkUrl(const Url &url)
Like setMirrorListUrl but expect metalink format.
static const RepoType RPMMD
void setGpgKeyUrls(url_set urls)
Set a list of gpgkey URLs defined for this repo.
const std::set< std::string > & contentKeywords() const
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
void setProbedType(const repo::RepoType &t) const
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
url_set::size_type urls_size_type
static const RepoType YAST2
bool hasSuffix(const C_Str &str_r, const C_Str &suffix_r)
Return whether str_r has suffix suffix_r.
void rawRepoGpgCheck(TriBool val_r)
url_set rawBaseUrls() const
The complete set of raw repository urls (no variables replaced)
void setTargetDistribution(const std::string &targetDistribution)
Sets the distribution for which is this repository meant.
bool needToAcceptLicense() const
Whether the repo license has to be accepted, e.g.
Base class for Exception.
virtual std::ostream & dumpAsIniOn(std::ostream &str) const
Write this RepoInfo object into str in a .repo file format.
static Date now()
Return the current time.
XmlString nodeText()
If the current node is not empty, advances the reader to the next node, and returns the value...
const RepoVariablesReplacedUrlList & gpgKeyUrls() const
std::string name() const
Repository name.
std::string asString() const
Explicit conversion to std::string.
Pathname licenseTgz(const std::string &name_r) const
Path to a license tarball in case it exists in the repo.
void setType(const repo::RepoType &t)
bool internalUnsignedConfirmed() const
We definitely have a symlink pointing to "indeterminate" (for repoGpgCheckIsMandatory)? I.e.
RepoVariablesReplacedUrlList _gpgKeyUrls
TriBool rawRepoGpgCheck() const
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
RepoVariablesReplacedUrl _mirrorListUrl
DefaultIntegral< unsigned, defaultPriority > priority
std::string targetDistribution() const
Distribution for which is this repository meant.
Pathname packagesPath() const
Path where this repo packages are cached.
void setBaseUrls(url_set urls)
Clears current base URL list and adds an url_set.
Wrapper class for ::stat/::lstat.
static const RepoInfo noRepo
Represents no Repository (one with an empty alias).
void setMetalinkUrls(url_set urls)
Like setMirrorListUrls but expect metalink format.
urls_const_iterator baseUrlsEnd() const
iterator that points at end of repository urls
void addContent(const std::string &keyword_r)
Add content keywords.
void rawPkgGpgCheck(TriBool val_r)
static const RepoType RPMPLAINDIR
bool autorefresh() const
If true, the repostory must be refreshed before creating resolvables from it.
static bool info(const std::string &msg_r, const UserData &userData_r=UserData())
send message text
urls_size_type baseUrlsSize() const
number of repository urls
const std::vector< Url > & getUrls() const
urls_size_type gpgKeyUrlsSize() const
Number of gpgkey URLs defined.
Pathname metadataPath() const
TriBool rawGpgCheck() const
Easy-to use interface to the ZYPP dependency resolver.
static const unsigned defaultPriority
Impl * clone() const
clone for RWCOW_pointer
static unsigned noPriority()
The least priority (unsigned(-1)).
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
url_set baseUrls() const
The complete set of repository urls.
void setPkgGpgCheck(TriBool value_r)
Set the value for pkgGpgCheck (or indeterminate to use the default).
repo::RepoType type() const
Type of repository,.
std::unordered_set< Locale > LocaleSet
TriBool cfgRepoGpgCheck() const
const char * c_str() const
void metadataPath(Pathname new_r)
detail::EscapedString escape(const std::string &in_r)
Escape xml special charaters (& -> &; from IoBind library).
Repository type enumeration.
bool hasContent(const std::string &keyword_r) const