15 #include <rpm/rpmcli.h> 16 #include <rpm/rpmlog.h> 58 #define WARNINGMAILPATH "/var/log/YaST2/" 59 #define FILEFORBACKUPFILES "YaSTBackupModifiedFiles" 60 #define MAXRPMMESSAGELINES 10000 62 #define WORKAROUNDRPMPWDBUG 64 #undef ZYPP_BASE_LOGGER_LOGGROUP 65 #define ZYPP_BASE_LOGGER_LOGGROUP "librpmDb" 69 namespace zypp_readonly_hack
79 #if 1 // No more need to escape whitespace since rpm-4.4.2.3 80 const char* quoteInFilename_m =
"\'\"";
82 const char* quoteInFilename_m =
" \t\'\"";
84 inline std::string rpmQuoteFilename(
const Pathname & path_r )
86 std::string path( path_r.
asString() );
88 pos != std::string::npos;
89 pos = path.find_first_of( quoteInFilename_m, pos ) )
91 path.insert( pos,
"\\" );
104 #if defined(WORKAROUNDRPMPWDBUG) 108 AutoDispose<char*> cwd( ::get_current_dir_name(), ::free );
111 WAR <<
"Can't get cwd!" << endl;
132 MIL <<
"trusted key added to zypp Keyring. Importing..." << endl;
133 _rpmdb.importPubkey( key );
138 MIL <<
"Trusted key removed from zypp Keyring. Removing..." << endl;
139 _rpmdb.removePubkey( key );
147 unsigned diffFiles(
const std::string file1,
const std::string file2, std::string& out,
int maxlines)
168 if (maxlines<0?
true:count<maxlines)
194 #define FAILIFNOTINITIALIZED if( ! initialized() ) { ZYPP_THROW(RpmDbNotOpenException()); } 205 : _backuppath (
"/var/adm/backup")
206 , _packagebackups(false)
213 setenv(
"RPM_IgnoreFailedSymlinks",
"1", 1 );
225 MIL <<
"~RpmDb()" << endl;
228 MIL <<
"~RpmDb() end" << endl;
254 bool quickinit( root_r.
empty() );
256 if ( root_r.
empty() )
267 ERR <<
"Illegal root or dbPath: " <<
stringPath( root_r, dbPath_r ) << endl;
271 if ( !
PathInfo( root_r/
"/var/lib/rpm" ).isExist()
272 &&
PathInfo( root_r/
"/usr/lib/sysimage/rpm" ).isDir() )
274 WAR <<
"Rpm package was deleted? Injecting missing rpmdb compat symlink." << endl;
278 MIL <<
"Calling initDatabase: " <<
stringPath( root_r, dbPath_r )
279 << ( doRebuild_r ?
" (rebuilddb)" :
"" )
280 << ( quickinit ?
" (quickinit)" :
"" ) << endl;
304 MIL <<
"QUICK initDatabase (no systemRoot set)" << endl;
326 MIL <<
"Synchronizing keys with zypp keyring" << endl;
335 MIL <<
"InitDatabase: " << *
this << endl;
351 MIL <<
"Calling closeDatabase: " << *
this << endl;
363 MIL <<
"closeDatabase: " << *
this << endl;
393 MIL <<
"RpmDb::rebuildDatabase" << *
this << endl;
407 opts.push_back(
"--rebuilddb");
408 opts.push_back(
"-vv");
418 tics.
range( hdrTotal );
429 static const std::string debugPrefix {
"D:" };
430 static const std::string progressPrefix {
"D: read h#" };
431 static const std::string ignoreSuffix {
"digest: OK" };
446 WAR <<
"User requested abort." << endl;
470 void computeKeyRingSync( std::set<Edition> & rpmKeys_r, std::list<PublicKeyData> & zyppKeys_r )
481 void updateIf(
const Edition & rpmKey_r )
483 std::string keyRelease( rpmKey_r.
release() );
484 int comp = _release.compare( keyRelease );
488 _release.swap( keyRelease );
489 _inRpmKeys = &rpmKey_r;
490 _inZyppKeys =
nullptr;
491 if ( !keyRelease.empty() )
492 DBG <<
"Old key in Z: gpg-pubkey-" << rpmKey_r.
version() <<
"-" << keyRelease << endl;
494 else if ( comp == 0 )
498 _inRpmKeys = &rpmKey_r;
502 DBG <<
"Old key in R: gpg-pubkey-" << rpmKey_r.
version() <<
"-" << keyRelease << endl;
505 void updateIf(
const PublicKeyData & zyppKey_r )
507 std::string keyRelease( zyppKey_r.gpgPubkeyRelease() );
508 int comp = _release.compare( keyRelease );
512 _release.swap( keyRelease );
513 _inRpmKeys =
nullptr;
514 _inZyppKeys = &zyppKey_r;
515 if ( !keyRelease.empty() )
516 DBG <<
"Old key in R: gpg-pubkey-" << zyppKey_r.gpgPubkeyVersion() <<
"-" << keyRelease << endl;
518 else if ( comp == 0 )
522 _inZyppKeys = &zyppKey_r;
526 DBG <<
"Old key in Z: gpg-pubkey-" << zyppKey_r.gpgPubkeyVersion() <<
"-" << keyRelease << endl;
529 std::string _release;
530 const Edition * _inRpmKeys;
531 const PublicKeyData * _inZyppKeys;
536 std::map<std::string,Key> _keymap;
538 for_( it, rpmKeys_r.begin(), rpmKeys_r.end() )
540 _keymap[(*it).version()].updateIf( *it );
543 for_( it, zyppKeys_r.begin(), zyppKeys_r.end() )
545 _keymap[(*it).gpgPubkeyVersion()].updateIf( *it );
549 std::set<Edition> rpmKeys;
550 std::list<PublicKeyData> zyppKeys;
551 for_( it, _keymap.begin(), _keymap.end() )
553 DBG <<
"gpg-pubkey-" << (*it).first <<
"-" << (*it).second._release <<
" " 554 << ( (*it).second._inRpmKeys ?
"R" :
"_" )
555 << ( (*it).second._inZyppKeys ?
"Z" :
"_" ) << endl;
556 if ( ! (*it).second._inRpmKeys )
558 zyppKeys.push_back( *(*it).second._inZyppKeys );
560 if ( ! (*it).second._inZyppKeys )
562 rpmKeys.insert( *(*it).second._inRpmKeys );
565 rpmKeys_r.swap( rpmKeys );
566 zyppKeys_r.swap( zyppKeys );
573 MIL <<
"Going to sync trusted keys..." << endl;
575 std::list<PublicKeyData> zyppKeys( getZYpp()->keyRing()->trustedPublicKeyData() );
587 MIL <<
"Removing excess keys in zypp trusted keyring" << std::endl;
593 if ( ! rpmKeys.count( keyData.gpgPubkeyEdition() ) )
595 DBG <<
"Excess key in Z to delete: gpg-pubkey-" << keyData.gpgPubkeyEdition() << endl;
596 getZYpp()->keyRing()->deleteKey( keyData.id(), true );
597 if ( !dirty ) dirty =
true;
601 zyppKeys = getZYpp()->keyRing()->trustedPublicKeyData();
604 computeKeyRingSync( rpmKeys, zyppKeys );
605 MIL << (mode_r &
SYNC_TO_KEYRING ?
"" :
"(skip) ") <<
"Rpm keys to export into zypp trusted keyring: " << rpmKeys.size() << endl;
606 MIL << (mode_r &
SYNC_FROM_KEYRING ?
"" :
"(skip) ") <<
"Zypp trusted keys to import into rpm database: " << zyppKeys.size() << endl;
612 MIL <<
"Exporting rpm keyring into zypp trusted keyring" <<endl;
617 TmpFile tmpfile( getZYpp()->tmpPath() );
619 std::ofstream tmpos( tmpfile.
path().
c_str() );
620 for_( it, rpmKeys.begin(), rpmKeys.end() )
624 getData(
"gpg-pubkey", *it, result );
625 tmpos << result->tag_description() << endl;
630 getZYpp()->keyRing()->multiKeyImport( tmpfile.
path(),
true );
634 std::set<Edition> missingKeys;
635 for (
const Edition & key : rpmKeys )
637 if ( getZYpp()->keyRing()->isKeyTrusted( key.version() ) )
639 ERR <<
"Could not import key:" <<
str::Format(
"gpg-pubkey-%s") % key <<
" into zypp keyring (V3 key?)" << endl;
640 missingKeys.insert( key );
642 if ( ! missingKeys.empty() )
648 ERR <<
"Could not import keys into zypp keyring: " << endl;
656 MIL <<
"Importing zypp trusted keyring" << std::endl;
657 for_( it, zyppKeys.begin(), zyppKeys.end() )
661 importPubkey( getZYpp()->keyRing()->exportTrustedPublicKey( *it ) );
669 MIL <<
"Trusted keys synced." << endl;
691 WAR <<
"Key " << pubkey_r <<
" can not be imported. (READONLY MODE)" << endl;
698 bool hasOldkeys =
false;
700 for_( it, rpmKeys.begin(), rpmKeys.end() )
709 MIL <<
"Key " << pubkey_r <<
" is already in the rpm trusted keyring. (skip import)" << endl;
713 if ( keyEd.version() != (*it).version() )
716 if ( keyEd.release() < (*it).release() )
718 MIL <<
"Key " << pubkey_r <<
" is older than one in the rpm trusted keyring. (skip import)" << endl;
726 MIL <<
"Key " << pubkey_r <<
" will be imported into the rpm trusted keyring." << (hasOldkeys?
"(update)":
"(new)") << endl;
732 std::string keyName(
"gpg-pubkey-" + keyEd.version() );
734 opts.push_back (
"-e" );
735 opts.push_back (
"--allmatches" );
736 opts.push_back (
"--" );
737 opts.push_back ( keyName.c_str() );
748 ERR <<
"Failed to remove key " << pubkey_r <<
" from RPM trusted keyring (ignored)" << endl;
752 MIL <<
"Key " << pubkey_r <<
" has been removed from RPM trusted keyring" << endl;
758 opts.push_back (
"--import" );
759 opts.push_back (
"--" );
761 opts.push_back ( pubkeypath.c_str() );
765 std::vector<std::string> excplines;
771 excplines.push_back( std::move(line) );
787 MIL <<
"Key " << pubkey_r <<
" imported in rpm trusted keyring." << endl;
804 std::set<Edition>::const_iterator found_edition = rpm_keys.end();
807 for_( it, rpm_keys.begin(), rpm_keys.end() )
809 if ( (*it).version() == pubkeyVersion )
817 if (found_edition == rpm_keys.end())
819 WAR <<
"Key " << pubkey_r.
id() <<
" is not in rpm db" << endl;
823 std::string rpm_name(
"gpg-pubkey-" + found_edition->asString());
826 opts.push_back (
"-e" );
827 opts.push_back (
"--" );
828 opts.push_back ( rpm_name.c_str() );
832 std::vector<std::string> excplines;
838 excplines.push_back( std::move(line) );
854 MIL <<
"Key " << pubkey_r <<
" has been removed from RPM trusted keyring" << endl;
866 std::list<PublicKey> ret;
869 for ( it.
findByName(
"gpg-pubkey" ); *it; ++it )
871 Edition edition = it->tag_edition();
876 getData(
"gpg-pubkey", edition, result );
877 TmpFile file(getZYpp()->tmpPath());
883 os << result->tag_description();
892 catch ( std::exception & e )
894 ERR <<
"Could not dump key " << edition.
asString() <<
" in tmp file " << file.
path() << endl;
904 std::set<Edition> ret;
907 for ( it.
findByName(
"gpg-pubkey" ); *it; ++it )
909 Edition edition = it->tag_edition();
911 ret.insert( edition );
928 std::list<FileInfo> result;
955 bool RpmDb::hasFile(
const std::string & file_r,
const std::string & name_r )
const 965 res = (it->tag_name() == name_r);
986 return it->tag_name();
1100 struct RpmlogCapture :
public std::string
1103 { rpmlog()._cap =
this; }
1106 { rpmlog()._cap =
nullptr; }
1114 rpmlogSetCallback( rpmLogCB,
this );
1115 rpmSetVerbosity( RPMLOG_INFO );
1116 _f = ::fopen(
"/dev/null",
"w");
1117 rpmlogSetFile(
_f );
1121 {
if (
_f ) ::fclose(
_f ); }
1123 static int rpmLogCB( rpmlogRec rec_r, rpmlogCallbackData data_r )
1124 {
return reinterpret_cast<Rpmlog*
>(data_r)->rpmLog( rec_r ); }
1126 int rpmLog( rpmlogRec rec_r )
1128 if (
_cap ) (*_cap) += rpmlogRecMessage( rec_r );
1129 return RPMLOG_DEFAULT;
1136 static Rpmlog & rpmlog()
1137 {
static Rpmlog _rpmlog;
return _rpmlog; }
1142 bool requireGPGSig_r,
1143 RpmDb::CheckPackageDetail & detail_r )
1146 if ( ! file.isFile() )
1148 ERR <<
"Not a file: " << file << endl;
1152 FD_t fd = ::Fopen( file.asString().c_str(),
"r.ufdio" );
1153 if ( fd == 0 || ::Ferror(fd) )
1155 ERR <<
"Can't open file for reading: " << file <<
" (" << ::Fstrerror(fd) <<
")" << endl;
1160 rpmts ts = ::rpmtsCreate();
1161 ::rpmtsSetRootDir( ts, root_r.
c_str() );
1162 ::rpmtsSetVSFlags( ts, RPMVSF_DEFAULT );
1164 rpmQVKArguments_s qva;
1165 memset( &qva, 0,
sizeof(rpmQVKArguments_s) );
1166 #ifdef HAVE_NO_RPMTSSETVFYFLAGS 1169 qva.qva_flags = (VERIFY_DIGEST|VERIFY_SIGNATURE);
1171 ::rpmtsSetVfyFlags( ts, RPMVSF_DEFAULT );
1173 RpmlogCapture vresult;
1174 LocaleGuard guard( LC_ALL,
"C" );
1175 int res = ::rpmVerifySignatures( &qva, ts, fd, path_r.
basename().c_str() );
1188 std::vector<std::string> lines;
1189 str::split( vresult, std::back_inserter(lines),
"\n" );
1190 unsigned count[7] = { 0, 0, 0, 0, 0, 0, 0 };
1192 for (
unsigned i = 1; i < lines.size(); ++i )
1194 std::string & line( lines[i] );
1196 if ( line.find(
": OK" ) != std::string::npos )
1199 if ( line.find(
"Signature, key ID" ) == std::string::npos )
1202 else if ( line.find(
": NOKEY" ) != std::string::npos )
1204 else if ( line.find(
": BAD" ) != std::string::npos )
1206 else if ( line.find(
": UNKNOWN" ) != std::string::npos )
1208 else if ( line.find(
": NOTRUSTED" ) != std::string::npos )
1212 detail_r.push_back( RpmDb::CheckPackageDetail::value_type( lineres, std::move(line) ) );
1233 detail_r.push_back( RpmDb::CheckPackageDetail::value_type(
RpmDb::CHK_NOSIG, std::string(
" ")+
_(
"Package is not signed!") ) );
1234 if ( requireGPGSig_r )
1241 WAR << path_r <<
" (" << requireGPGSig_r <<
" -> " << ret <<
")" << endl;
1254 {
return doCheckPackageSig( path_r,
root(),
false, detail_r ); }
1260 {
return doCheckPackageSig( path_r,
root(),
true, detail_r ); }
1275 opts.push_back (
"-V");
1276 opts.push_back (
"--nodeps");
1277 opts.push_back (
"--noscripts");
1278 opts.push_back (
"--nomd5");
1279 opts.push_back (
"--");
1280 opts.push_back (packageName.c_str());
1301 if (line.length() > 12 &&
1302 (line[0] ==
'S' || line[0] ==
's' ||
1303 (line[0] ==
'.' && line[7] ==
'T')))
1306 std::string filename;
1308 filename.assign(line, 11, line.length() - 11);
1349 #if defined(WORKAROUNDRPMPWDBUG) 1350 args.push_back(
"#/");
1352 args.push_back(
"rpm");
1353 args.push_back(
"--root");
1355 args.push_back(
"--dbpath");
1358 const char* argv[args.size() + opts.size() + 1];
1360 const char** p = argv;
1361 p =
copy (args.begin (), args.end (), p);
1362 p =
copy (opts.begin (), opts.end (), p);
1388 int inputfileFd = ::fileno( inputfile );
1394 FD_SET( inputfileFd, &rfds );
1401 int retval = select( inputfileFd+1, &rfds, NULL, NULL, &tv );
1405 ERR <<
"select error: " <<
strerror(errno) << endl;
1406 if ( errno != EINTR )
1412 static size_t linebuffer_size = 0;
1413 static char * linebuffer = 0;
1414 ssize_t nread =
getline( &linebuffer, &linebuffer_size, inputfile );
1417 if ( ::feof( inputfile ) )
1424 if ( linebuffer[nread-1] ==
'\n' )
1426 line += std::string( linebuffer, nread );
1429 if ( ! ::ferror( inputfile ) || ::feof( inputfile ) )
1432 clearerr( inputfile );
1481 void RpmDb::processConfigFiles(
const std::string& line,
const std::string& name,
const char* typemsg,
const char* difffailmsg,
const char* diffgenmsg)
1483 std::string msg = line.substr(9);
1486 std::string file1s, file2s;
1490 pos1 = msg.find (typemsg);
1493 if ( pos1 == std::string::npos )
1496 pos2 = pos1 + strlen (typemsg);
1498 if (pos2 >= msg.length() )
1501 file1 = msg.substr (0, pos1);
1502 file2 = msg.substr (pos2);
1509 file1 =
_root + file1;
1510 file2 =
_root + file2;
1520 ERR <<
"Could not create " << file.
asString() << endl;
1524 std::ofstream notify(file.
asString().c_str(), std::ios::out|std::ios::app);
1527 ERR <<
"Could not open " << file << endl;
1533 notify <<
str::form(
_(
"Changed configuration files for %s:"), name.c_str()) << endl;
1536 ERR <<
"diff failed" << endl;
1538 file1s.c_str(), file2s.c_str()) << endl;
1543 file1s.c_str(), file2s.c_str()) << endl;
1548 if (out.substr(0,4) ==
"--- ")
1550 out.replace(4, file1.
asString().length(), file1s);
1553 if (pos != std::string::npos)
1555 out.replace(pos+5, file2.
asString().length(), file2s);
1558 notify << out << endl;
1561 notify.open(
"/var/lib/update-messages/yast2-packagemanager.rpmdb.configfiles");
1566 WAR <<
"rpm created " << file2 <<
" but it is not different from " << file2 << endl;
1597 report->finish( excpt_r );
1613 MIL <<
"RpmDb::installPackage(" << filename <<
"," << flags <<
")" << endl;
1622 ERR <<
"backup of " << filename.
asString() <<
" failed" << endl;
1631 opts.push_back(
"-i");
1633 opts.push_back(
"-U");
1635 opts.push_back(
"--percent");
1636 opts.push_back(
"--noglob");
1640 opts.push_back(
"--ignorearch");
1643 opts.push_back(
"--nodigest");
1645 opts.push_back(
"--nosignature");
1647 opts.push_back (
"--excludedocs");
1649 opts.push_back (
"--noscripts");
1651 opts.push_back (
"--force");
1653 opts.push_back (
"--nodeps");
1655 opts.push_back (
"--ignoresize");
1657 opts.push_back (
"--justdb");
1659 opts.push_back (
"--test");
1661 opts.push_back (
"--noposttrans");
1663 opts.push_back(
"--");
1666 std::string quotedFilename( rpmQuoteFilename( workaroundRpmPwdBug( filename ) ) );
1667 opts.push_back ( quotedFilename.c_str() );
1672 std::vector<std::string> configwarnings;
1674 unsigned linecnt = 0;
1680 sscanf( line.c_str() + 2,
"%d", &percent );
1681 report->progress( percent );
1687 else if ( line.find(
" scriptlet failed, " ) == std::string::npos )
1690 rpmmsg += line+
'\n';
1693 configwarnings.push_back(line);
1696 rpmmsg +=
"[truncated]\n";
1701 for (std::vector<std::string>::iterator it = configwarnings.begin();
1702 it != configwarnings.end(); ++it)
1706 _(
"rpm saved %s as %s, but it was impossible to determine the difference"),
1708 _(
"rpm saved %s as %s.\nHere are the first 25 lines of difference:\n"));
1711 _(
"rpm created %s as %s, but it was impossible to determine the difference"),
1713 _(
"rpm created %s as %s.\nHere are the first 25 lines of difference:\n"));
1716 if ( rpm_status != 0 )
1721 std::ostringstream sstr;
1722 sstr <<
"rpm output:" << endl << rpmmsg << endl;
1723 historylog.
comment(sstr.str());
1727 else if ( ! rpmmsg.empty() )
1732 std::ostringstream sstr;
1733 sstr <<
"Additional rpm output:" << endl << rpmmsg << endl;
1734 historylog.
comment(sstr.str());
1738 report->finishInfo(
str::form(
"%s:\n%s\n",
_(
"Additional rpm output"), rpmmsg.c_str() ));
1752 +
"-" + package->edition().version()
1753 +
"-" + package->edition().release()
1754 +
"." + package->arch().asString(), flags );
1782 report->finish( excpt_r );
1799 MIL <<
"RpmDb::doRemovePackage(" << name_r <<
"," << flags <<
")" << endl;
1808 ERR <<
"backup of " << name_r <<
" failed" << endl;
1819 opts.push_back(
"-e");
1820 opts.push_back(
"--allmatches");
1823 opts.push_back(
"--noscripts");
1825 opts.push_back(
"--nodeps");
1827 opts.push_back(
"--justdb");
1829 opts.push_back (
"--test");
1832 WAR <<
"IGNORE OPTION: 'rpm -e' does not support '--force'" << endl;
1835 opts.push_back(
"--");
1836 opts.push_back(name_r.c_str());
1847 unsigned linecnt = 0;
1852 else if ( line.find(
" scriptlet failed, " ) == std::string::npos )
1854 rpmmsg += line+
'\n';
1857 rpmmsg +=
"[truncated]\n";
1861 if ( rpm_status != 0 )
1864 str::form(
"%s remove failed", name_r.c_str()),
true );
1865 std::ostringstream sstr;
1866 sstr <<
"rpm output:" << endl << rpmmsg << endl;
1867 historylog.
comment(sstr.str());
1871 else if ( ! rpmmsg.empty() )
1874 str::form(
"%s removed ok", name_r.c_str()),
true );
1876 std::ostringstream sstr;
1877 sstr <<
"Additional rpm output:" << endl << rpmmsg << endl;
1878 historylog.
comment(sstr.str());
1882 report->finishInfo(
str::form(
"%s:\n%s\n",
_(
"Additional rpm output"), rpmmsg.c_str() ));
1916 INT <<
"_backuppath empty" << endl;
1924 ERR <<
"Error while getting changed files for package " <<
1925 packageName << endl;
1931 DBG <<
"package " << packageName <<
" not changed -> no backup" << endl;
1943 struct tm *currentLocalTime = localtime(&
currentTime);
1945 int date = (currentLocalTime->tm_year + 1900) * 10000
1946 + (currentLocalTime->tm_mon + 1) * 100
1947 + currentLocalTime->tm_mday;
1953 +
str::form(
"%s-%d-%d.tar.gz",packageName.c_str(), date, num);
1961 ERR << filestobackupfile.
asString() <<
" already exists and is no file" << endl;
1965 std::ofstream fp ( filestobackupfile.
asString().c_str(), std::ios::out|std::ios::trunc );
1969 ERR <<
"could not open " << filestobackupfile.
asString() << endl;
1973 for (FileList::const_iterator cit =
fileList.begin();
1976 std::string name = *cit;
1977 if ( name[0] ==
'/' )
1980 name = name.substr( 1 );
1982 DBG <<
"saving file "<< name << endl;
1987 const char*
const argv[] =
1993 "--ignore-failed-read",
1997 filestobackupfile.
asString().c_str(),
2013 int ret = tar.
close();
2017 ERR <<
"tar failed: " << tarmsg << endl;
2022 MIL <<
"tar backup ok" << endl;
2043 #define OUTS(E,S) case RpmDb::E: return str << "["<< (unsigned)obj << "-"<< S << "]"; break 2045 OUTS( CHK_OK,
_(
"Signature is OK") );
2047 OUTS( CHK_NOTFOUND,
_(
"Unknown type of signature") );
2049 OUTS( CHK_FAIL,
_(
"Signature does not verify") );
2051 OUTS( CHK_NOTTRUSTED,
_(
"Signature is OK, but key is not trusted") );
2053 OUTS( CHK_NOKEY,
_(
"Signatures public key is not available") );
2055 OUTS( CHK_ERROR,
_(
"File does not exist or signature can't be checked") );
2057 OUTS( CHK_NOSIG,
_(
"File is unsigned") );
2065 for (
const auto & el : obj )
2066 str << el.second << endl;
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
Interface to the rpm program.
unsigned diffFiles(const std::string file1, const std::string file2, std::string &out, int maxlines)
CheckPackageResult checkPackageSignature(const Pathname &path_r, CheckPackageDetail &detail_r)
Check signature of rpm file on disk (strict check returning CHK_NOSIG if file is unsigned).
bool hasRequiredBy(const std::string &tag_r) const
Return true if at least one package requires a certain tag.
static unsigned blockAccess()
Blocks further access to rpmdb.
void getData(const std::string &name_r, RpmHeader::constPtr &result_r) const
Get an installed packages data from rpmdb.
void sendTo(const ReceiverFnc &fnc_r)
Set ReceiverFnc.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
virtual void trustedKeyAdded(const PublicKey &key)
bool kill()
Kill the program.
static ZConfig & instance()
Singleton ctor.
Pathname _root
Root directory for all operations.
bool findByProvides(const std::string &tag_r)
Reset to iterate all packages that provide a certain tag.
Class representing one GPG Public Keys data.
void exportTrustedKeysInZyppKeyRing()
insert all rpm trusted keys into zypp trusted keyring
static void dbAccess()
Access the database at the current default location.
void rebuildDatabase()
Rebuild the rpm database (rpm –rebuilddb).
void installPackage(const Pathname &filename, RpmInstFlags flags=RPMINST_NONE)
install rpm package
std::ostream & operator<<(std::ostream &str, const librpmDb::db_const_iterator &obj)
const char * c_str() const
String representation.
String related utilities and Regular expression matching.
bool toMax()
Set counter value to current max value (unless no range).
bool findByRequiredBy(const std::string &tag_r)
Reset to iterate all packages that require a certain tag.
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Edition represents [epoch:]version[-release]
bool running()
Return whether program is running.
std::string receiveLine()
Read one line from the input stream.
bool hasSubkeys() const
!<
std::string basename() const
Return the last component of this path.
Provide a new empty temporary file and delete it when no longer needed.
void importZyppKeyRingTrustedKeys()
iterates through zypp keyring and import all non existant keys into rpm keyring
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
bool backupPackage(const std::string &packageName)
create tar.gz of all changed files in a Package
CheckPackageResult checkPackage(const Pathname &path_r, CheckPackageDetail &detail_r)
Check signature of rpm file on disk (legacy version returning CHK_OK if file is unsigned, like 'rpm -K')
#define FILEFORBACKUPFILES
void range(value_type max_r)
Set new [0,max].
Subclass to retrieve database content.
Temporarily connect a ReceiveReport then restore the previous one.
void importPubkey(const PublicKey &pubkey_r)
Import ascii armored public key in file pubkey_r.
Assign a vaiable a certain value when going out of scope.
bool hasPackage(const std::string &name_r) const
Return true if package is installed.
void systemKill()
Forcably kill the system process.
bool empty() const
Test for an empty path.
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
void moveToHistory(TContainer &&msgc_r)
addHistory from string container types (oldest first) moving
bool toMin()
Set counter value to current min value.
void syncTrustedKeys(SyncTrustedKeyBits mode_r=SYNC_BOTH)
Sync trusted keys stored in rpm database and zypp trusted keyring.
#define FAILIFNOTINITIALIZED
std::string getline(std::istream &str)
Read one line from stream.
Store and operate on date (time_t).
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.
const std::string & execError() const
Some detail telling why the execution failed, if it failed.
Pathname _backuppath
/var/adm/backup
std::string version() const
Version.
shared_ptr< RpmException > dbError() const
Return any database error.
std::string form(const std::string &format_r) const
Return string representation according to format as localtime.
std::string asString() const
int exit_code
The exit code of the rpm process, or -1 if not yet known.
std::list< PublicKey > pubkeys() const
Return the long ids of all installed public keys.
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'.
std::string gpgPubkeyVersion() const
SyncTrustedKeyBits
Sync mode for syncTrustedKeys.
bool systemReadLine(std::string &line)
Read a line from the general rpm query.
const std::string & asString() const
String representation.
int systemStatus()
Return the exit status of the general rpm process, closing the connection if not already done...
std::set< Edition > pubkeyEditions() const
Return the edition of all installed public keys.
bool isExist() const
Return whether valid stat info exists.
static const Pathname & defaultDbPath()
bool findByName(const std::string &name_r)
Reset to iterate all packages with a certain name.
std::string asUserHistory() const
A single (multiline) string composed of asUserString and historyAsString.
std::string release() const
Release.
Detailed rpm signature check log messages A single multiline message if CHK_OK.
virtual std::ostream & dumpOn(std::ostream &str) const
Dump debug info.
bool startsWith(const C_Str &str_r, const C_Str &prefix_r)
alias for hasPrefix
Types and functions for filesystem operations.
static unsigned dbRelease(bool force_r=false)
If there are no outstanding references to the database (e.g.
static shared_ptr< KeyRingSignalReceiver > sKeyRingReceiver
Maintain [min,max] and counter (value) for progress counting.
ExternalProgram * process
The connection to the rpm process.
Writing the zypp history fileReference counted signleton for writhing the zypp history file...
void doRebuildDatabase(callback::SendReport< RebuildDBReport > &report)
bool incr(value_type val_r=1)
Increment counter value (default by 1).
void initDatabase(Pathname root_r=Pathname(), bool doRebuild_r=false)
Prepare access to the rpm database at /var/lib/rpm.
bool absolute() const
Test for an absolute path.
int symlink(const Pathname &oldpath, const Pathname &newpath)
Like 'symlink'.
bool findByFile(const std::string &file_r)
Reset to iterate all packages that own a certain file.
void closeDatabase()
Block further access to the rpm database and go back to uninitialized state.
Stderr_Disposition
Define symbols for different policies on the handling of stderr.
bool hasProvides(const std::string &tag_r) const
Return true if at least one package provides a certain tag.
Just inherits Exception to separate media exceptions.
bool endsWith(const C_Str &str_r, const C_Str &prefix_r)
alias for hasSuffix
std::string numstring(char n, int w=0)
import zypp trusted keys into rpm database.
virtual void trustedKeyRemoved(const PublicKey &key)
bool findPackage(const std::string &name_r)
Find package by name.
static void unblockAccess()
Allow access to rpmdb e.g.
std::ostream & copy(std::istream &from_r, std::ostream &to_r)
Copy istream to ostream.
void doInstallPackage(const Pathname &filename, RpmInstFlags flags, callback::SendReport< RpmInstallReport > &report)
int close()
Wait for the progamm to complete.
void removePubkey(const PublicKey &pubkey_r)
Remove a public key from the rpm database.
void processConfigFiles(const std::string &line, const std::string &name, const char *typemsg, const char *difffailmsg, const char *diffgenmsg)
handle rpm messages like "/etc/testrc saved as /etc/testrc.rpmorig"
bool _packagebackups
create package backups?
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
std::string gpgPubkeyRelease() const
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
void doRemovePackage(const std::string &name_r, RpmInstFlags flags, callback::SendReport< RpmRemoveReport > &report)
Base class for Exception.
void setBackupPath(const Pathname &path)
set path where package backups are stored
const Pathname & root() const
bool hasConflicts(const std::string &tag_r) const
Return true if at least one package conflicts with a certain tag.
Pathname path() const
File containig the ASCII armored key.
const Pathname & dbPath() const
static Date now()
Return the current time.
std::string error_message
Error message from running rpm as external program.
std::string whoOwnsFile(const std::string &file_r) const
Return name of package owning file or empty string if no installed package owns file.
void removePackage(const std::string &name_r, RpmInstFlags flags=RPMINST_NONE)
remove rpm package
static bool globalInit()
Initialize lib librpm (read configfiles etc.).
std::list< FileInfo > fileList(const std::string &name_r, const Edition &edition_r) const
return complete file list for installed package name_r (in FileInfo.filename) if edition_r != Edition...
std::string asString() const
bool relative() const
Test for a relative path.
value_type reportValue() const
bool hasFile(const std::string &file_r, const std::string &name_r="") const
Return true if at least one package owns a certain file (name_r empty) Return true if package name_r ...
void comment(const std::string &comment, bool timestamp=false)
Log a comment (even multiline).
bool findByConflicts(const std::string &tag_r)
Reset to iterate all packages that conflict with a certain tag.
Wrapper class for ::stat/::lstat.
void setBlocking(bool mode)
Set the blocking mode of the input stream.
CheckPackageResult
checkPackage result
std::string stringPath(const Pathname &root_r, const Pathname &sub_r)
bool queryChangedFiles(FileList &fileList, const std::string &packageName)
determine which files of an installed package have been modified.
Pathname expandlink(const Pathname &path_r)
Recursively follows the symlink pointed to by path_r and returns the Pathname to the real file or dir...
FILE * inputFile() const
Return the input stream.
std::string strerror(int errno_r)
Return string describing the error_r code.
Easy-to use interface to the ZYPP dependency resolver.
void run_rpm(const RpmArgVec &options, ExternalProgram::Stderr_Disposition stderr_disp=ExternalProgram::Stderr_To_Stdout)
Run rpm with the specified arguments and handle stderr.
export rpm trusted keys into zypp trusted keyring
KeyRingSignalReceiver(RpmDb &rpmdb)
TraitsType::constPtrType constPtr
#define MAXRPMMESSAGELINES
static const Edition noedition
Value representing noedition ("") This is in fact a valid Edition.
Pathname _dbPath
Directory that contains the rpmdb.
std::set< std::string > FileList
std::vector< const char * > RpmArgVec