From: DongHun Kwak Date: Tue, 1 Nov 2016 01:49:00 +0000 (+0900) Subject: Imported Upstream version 15.12.0 X-Git-Tag: upstream/16.3.1~54 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F72%2F94672%2F1;p=platform%2Fupstream%2Flibzypp.git Imported Upstream version 15.12.0 Change-Id: If1b8995eacdff84672ee22b336cc7499b1f2e0aa Signed-off-by: DongHun Kwak --- diff --git a/VERSION.cmake b/VERSION.cmake index 4a3ae13..3ede5f0 100644 --- a/VERSION.cmake +++ b/VERSION.cmake @@ -60,9 +60,9 @@ # SET(LIBZYPP_MAJOR "15") SET(LIBZYPP_COMPATMINOR "11") -SET(LIBZYPP_MINOR "11") +SET(LIBZYPP_MINOR "12") SET(LIBZYPP_PATCH "0") # -# LAST RELEASED: 15.11.0 (11) +# LAST RELEASED: 15.12.0 (11) # (The number in parenthesis is LIBZYPP_COMPATMINOR) #======= diff --git a/package/libzypp.changes b/package/libzypp.changes index af9af4c..5b56a0d 100644 --- a/package/libzypp.changes +++ b/package/libzypp.changes @@ -1,4 +1,15 @@ ------------------------------------------------------------------- +Tue Aug 11 18:48:57 CEST 2015 - ma@suse.de + +- History: Add 'command' tag showing who triggered the commit. + The corresponding HistoryLogData class for parsing is + HistoryLogDataStampCommand. Available data are the commandline + executed, user@hostname and userdata/transactionID. (FATE#312298) +- Add convenience comparison PoolItem<>ResObject::constPtr +- Fixes for SWIG 2.x +- version 15.12.0 (11) + +------------------------------------------------------------------- Mon Aug 10 16:22:06 CEST 2015 - ma@suse.de - Make multiversion an individual solvables property (FATE#318778) diff --git a/tests/parser/HistoryLogReader_test.cc b/tests/parser/HistoryLogReader_test.cc index 7300ab3..0226cc5 100644 --- a/tests/parser/HistoryLogReader_test.cc +++ b/tests/parser/HistoryLogReader_test.cc @@ -34,7 +34,7 @@ BOOST_AUTO_TEST_CASE(basic) history.clear(); parser.readAll(); - BOOST_CHECK_EQUAL( history.size(), 7 ); + BOOST_CHECK_EQUAL( history.size(), 8 ); BOOST_CHECK( dynamic_pointer_cast ( history[0] ) ); BOOST_CHECK( dynamic_pointer_cast ( history[1] ) ); BOOST_CHECK( dynamic_pointer_cast ( history[2] ) ); @@ -42,6 +42,7 @@ BOOST_AUTO_TEST_CASE(basic) BOOST_CHECK( dynamic_pointer_cast ( history[4] ) ); BOOST_CHECK( dynamic_pointer_cast ( history[5] ) ); BOOST_CHECK( dynamic_pointer_cast ( history[6] ) ); + BOOST_CHECK( dynamic_pointer_cast ( history[7] ) ); BOOST_CHECK_EQUAL( (*history[1])[HistoryLogDataInstall::USERDATA_INDEX], "trans|ID" ); // properly (un)escaped? HistoryLogDataInstall::Ptr p = dynamic_pointer_cast( history[1] ); diff --git a/tests/parser/HistoryLogReader_test.dat b/tests/parser/HistoryLogReader_test.dat index 26c7d67..a3f9845 100644 --- a/tests/parser/HistoryLogReader_test.dat +++ b/tests/parser/HistoryLogReader_test.dat @@ -10,3 +10,4 @@ 2010-06-01 16:11:17|bad |unknown action field discard\|one field discard|to fields but bad date +2015-08-11 18:42:49|command|root@fibonacci|'/Local/ma/zypp/BUILD/zypper/src/zypper' 'in' '-f' 'xteddy'| diff --git a/zypp/HistoryLog.cc b/zypp/HistoryLog.cc index 5f1a8fd..310a4e9 100644 --- a/zypp/HistoryLog.cc +++ b/zypp/HistoryLog.cc @@ -16,6 +16,7 @@ #include "zypp/ZConfig.h" #include "zypp/base/String.h" #include "zypp/base/Logger.h" +#include "zypp/base/IOStream.h" #include "zypp/PathInfo.h" #include "zypp/Date.h" @@ -30,44 +31,75 @@ using std::endl; using std::string; -namespace +namespace zypp { - inline string timestamp() - { return zypp::Date::now().form( HISTORY_LOG_DATE_FORMAT ); } - - inline string userAtHostname() + namespace { - static char buf[256]; - string result; - char * tmp = ::cuserid(buf); - if (tmp) + inline string timestamp() + { return zypp::Date::now().form( HISTORY_LOG_DATE_FORMAT ); } + + inline string userAtHostname() { - result = string(tmp); - if (!::gethostname(buf, 255)) - result += "@" + string(buf); + static char buf[256]; + string result; + char * tmp = ::cuserid(buf); + if (tmp) + { + result = string(tmp); + if (!::gethostname(buf, 255)) + result += "@" + string(buf); + } + return result; } - return result; - } - static std::string pidAndAppname() - { - static std::string _val; - if ( _val.empty() ) + static std::string pidAndAppname() { - pid_t mypid = getpid(); - zypp::Pathname p( "/proc/"+zypp::str::numstring(mypid)+"/exe" ); - zypp::Pathname myname( zypp::filesystem::readlink( p ) ); + static std::string _val; + if ( _val.empty() ) + { + pid_t mypid = getpid(); + zypp::Pathname p( "/proc/"+zypp::str::numstring(mypid)+"/exe" ); + zypp::Pathname myname( zypp::filesystem::readlink( p ) ); - _val += zypp::str::numstring(mypid); - _val += ":"; - _val += myname.basename(); + _val += zypp::str::numstring(mypid); + _val += ":"; + _val += myname.basename(); + } + return _val; } - return _val; - } -} -namespace zypp -{ + static std::string cmdline() + { + static std::string _val; + if ( _val.empty() ) + { + pid_t mypid = getpid(); + { + std::ifstream cmdlineStr( Pathname("/proc/"+zypp::str::numstring(mypid)+"/cmdline").c_str() ); + char ch; + const char * sep = "'"; + while ( cmdlineStr && cmdlineStr.get( ch ) ) + { + if ( sep ) + { + _val += sep; + sep = nullptr; + } + switch ( ch ) + { + case '\0': _val += '\''; sep = " '"; break; + case '\n': _val += ' '; break; + case '\\': _val += '\\'; _val += '\\'; break; + case '|': _val += '\\'; _val += '|'; break; + default: _val += ch; break; + } + } + } + } + return _val; + } + } // namespace + namespace { const char _sep = '|'; @@ -109,7 +141,7 @@ namespace zypp if ( !_refcnt ) closeLog(); } - } + } // namespace /////////////////////////////////////////////////////////////////// // @@ -153,14 +185,14 @@ namespace zypp ///////////////////////////////////////////////////////////////////////// - void HistoryLog::comment( const string & comment, bool timestamp ) + void HistoryLog::comment( const string & comment, bool timestamp_r ) { if (comment.empty()) return; _log << "# "; - if ( timestamp ) - _log << ::timestamp() << " "; + if ( timestamp_r ) + _log << timestamp() << " "; const char * s = comment.c_str(); const char * c = s; @@ -185,6 +217,18 @@ namespace zypp ///////////////////////////////////////////////////////////////////////// + void HistoryLog::stampCommand() + { + _log + << timestamp() // 1 timestamp + << _sep << HistoryActionID::STAMP_COMMAND.asString(true) // 2 action + << _sep << userAtHostname() // 3 requested by + << _sep << cmdline() // 4 command + << _sep << str::escape(ZConfig::instance().userData(), _sep) // 6 userdata + << endl; + + } + void HistoryLog::install( const PoolItem & pi ) { const Package::constPtr p = asKind(pi.resolvable()); @@ -200,7 +244,7 @@ namespace zypp // ApplLow is what the solver selected on behalf of the user. if (pi.status().isByUser() || pi.status().isByApplLow() ) - _log << _sep << userAtHostname(); // 6 reqested by + _log << _sep << userAtHostname(); // 6 requested by else if (pi.status().isByApplHigh()) _log << _sep << pidAndAppname(); else @@ -229,7 +273,7 @@ namespace zypp // ApplLow is what the solver selected on behalf of the user. if ( pi.status().isByUser() || pi.status().isByApplLow() ) - _log << _sep << userAtHostname(); // 6 reqested by + _log << _sep << userAtHostname(); // 6 requested by else if (pi.status().isByApplHigh()) _log << _sep << pidAndAppname(); else diff --git a/zypp/HistoryLog.h b/zypp/HistoryLog.h index 9ac4959..de18f23 100644 --- a/zypp/HistoryLog.h +++ b/zypp/HistoryLog.h @@ -88,6 +88,9 @@ namespace zypp */ void comment( const std::string & comment, bool timestamp = false ); + /** Log info about the current process. */ + void stampCommand(); + /** * Log installation (or update) of a package. */ diff --git a/zypp/HistoryLogData.cc b/zypp/HistoryLogData.cc index 6ad34ce..e5e44fd 100644 --- a/zypp/HistoryLogData.cc +++ b/zypp/HistoryLogData.cc @@ -39,6 +39,7 @@ namespace zypp const HistoryActionID HistoryActionID::REPO_REMOVE (HistoryActionID::REPO_REMOVE_e); const HistoryActionID HistoryActionID::REPO_CHANGE_ALIAS (HistoryActionID::REPO_CHANGE_ALIAS_e); const HistoryActionID HistoryActionID::REPO_CHANGE_URL (HistoryActionID::REPO_CHANGE_URL_e); + const HistoryActionID HistoryActionID::STAMP_COMMAND (HistoryActionID::STAMP_COMMAND_e); HistoryActionID::HistoryActionID(const std::string & strval_r) : _id(parse(strval_r)) @@ -57,6 +58,7 @@ namespace zypp _table["rremove"] = REPO_REMOVE_e; _table["ralias"] = REPO_CHANGE_ALIAS_e; _table["rurl"] = REPO_CHANGE_URL_e; + _table["command"] = STAMP_COMMAND_e; _table["NONE"] = _table["none"] = NONE_e; } @@ -83,6 +85,7 @@ namespace zypp _table[REPO_REMOVE_e] = PairType( "rremove" , "rremove" ); _table[REPO_CHANGE_ALIAS_e] = PairType( "ralias" , "ralias " ); _table[REPO_CHANGE_URL_e] = PairType( "rurl" , "rurl " ); + _table[STAMP_COMMAND_e] = PairType( "command" , "command" ); _table[NONE_e] = PairType( "NONE" , "NONE " ); } @@ -188,6 +191,7 @@ namespace zypp OUTS( REPO_REMOVE_e, HistoryLogDataRepoRemove ); OUTS( REPO_CHANGE_ALIAS_e, HistoryLogDataRepoAliasChange ); OUTS( REPO_CHANGE_URL_e, HistoryLogDataRepoUrlChange ); + OUTS( STAMP_COMMAND_e, HistoryLogDataStampCommand ); #undef OUTS // intentionally no default: case HistoryActionID::NONE_e: @@ -295,5 +299,15 @@ namespace zypp Url HistoryLogDataRepoUrlChange::newUrl() const { return optionalAt( NEWURL_INDEX ); } std::string HistoryLogDataRepoUrlChange::userdata() const { return optionalAt( USERDATA_INDEX ); } + /////////////////////////////////////////////////////////////////// + // class HistoryLogDataStampCommand + /////////////////////////////////////////////////////////////////// + HistoryLogDataStampCommand::HistoryLogDataStampCommand( FieldVector & fields_r ) + : HistoryLogData( fields_r ) + {} + std::string HistoryLogDataStampCommand::executedBy() const { return optionalAt( USER_INDEX ); } + std::string HistoryLogDataStampCommand::command() const { return optionalAt( COMMAND_INDEX ); } + std::string HistoryLogDataStampCommand::userdata() const { return optionalAt( USERDATA_INDEX ); } + } // namespace zypp /////////////////////////////////////////////////////////////////// diff --git a/zypp/HistoryLogData.h b/zypp/HistoryLogData.h index 0428589..515acb8 100644 --- a/zypp/HistoryLogData.h +++ b/zypp/HistoryLogData.h @@ -43,6 +43,7 @@ namespace zypp static const HistoryActionID REPO_REMOVE; static const HistoryActionID REPO_CHANGE_ALIAS; static const HistoryActionID REPO_CHANGE_URL; + static const HistoryActionID STAMP_COMMAND; enum ID { @@ -53,7 +54,8 @@ namespace zypp REPO_ADD_e, REPO_REMOVE_e, REPO_CHANGE_ALIAS_e, - REPO_CHANGE_URL_e + REPO_CHANGE_URL_e, + STAMP_COMMAND_e }; HistoryActionID() : _id(NONE_e) {} @@ -382,6 +384,38 @@ namespace zypp std::string userdata() const; ///< userdata/transactionID }; + /////////////////////////////////////////////////////////////////// + /// \class HistoryLogDataStampCommand + /// \brief A zypp history log line identifying the program that + /// triggered the following commit. + /// \ingroup g_ZyppHistory + /////////////////////////////////////////////////////////////////// + class HistoryLogDataStampCommand : public HistoryLogData + { + public: + typedef shared_ptr Ptr; + typedef shared_ptr constPtr; + /** Ctor \b moving \a FieldVector (via swap). + * \throws ParseException if \a fields_r has the wrong \ref HistoryActionID or number of fields. + */ + HistoryLogDataStampCommand( FieldVector & fields_r ); + + public: + enum Index ///< indices of known fields + { + DATE_INDEX = HistoryLogData::DATE_INDEX, + ACTION_INDEX = HistoryLogData::ACTION_INDEX, + USER_INDEX, ///< executed by user@hostname + COMMAND_INDEX, ///< the commandline executed + USERDATA_INDEX, ///< userdata/transactionID + }; + + public: + std::string executedBy() const; ///< executed by user@hostname + std::string command() const; ///< the commandline executed + std::string userdata() const; ///< userdata/transactionID + }; + } // namespace zypp /////////////////////////////////////////////////////////////////// #endif /* ZYPP_HISTORYLOGDATA_H_ */ diff --git a/zypp/PoolItem.h b/zypp/PoolItem.h index c307401..922ad53 100644 --- a/zypp/PoolItem.h +++ b/zypp/PoolItem.h @@ -165,6 +165,32 @@ namespace zypp /** \relates PoolItem Stream output */ std::ostream & operator<<( std::ostream & str, const PoolItem & obj ); + + /** \relates PoolItem Required to disambiguate vs. (PoolItem,ResObject::constPtr) due to implicit PoolItem::operator ResObject::constPtr */ + inline bool operator==( const PoolItem & lhs, const PoolItem & rhs ) + { return lhs.resolvable() == rhs.resolvable(); } + + /** \relates PoolItem Convenience compare */ + inline bool operator==( const PoolItem & lhs, const ResObject::constPtr & rhs ) + { return lhs.resolvable() == rhs; } + + /** \relates PoolItem Convenience compare */ + inline bool operator==( const ResObject::constPtr & lhs, const PoolItem & rhs ) + { return lhs == rhs.resolvable(); } + + + /** \relates PoolItem Required to disambiguate vs. (PoolItem,ResObject::constPtr) due to implicit PoolItem::operator ResObject::constPtr */ + inline bool operator!=( const PoolItem & lhs, const PoolItem & rhs ) + { return ! (lhs==rhs); } + + /** \relates PoolItem Convenience compare */ + inline bool operator!=( const PoolItem & lhs, const ResObject::constPtr & rhs ) + { return ! (lhs==rhs); } + + /** \relates PoolItem Convenience compare */ + inline bool operator!=( const ResObject::constPtr & lhs, const PoolItem & rhs ) + { return ! (lhs==rhs); } + /** Solvable to PoolItem transform functor. * \relates PoolItem * \relates sat::SolvIterMixin diff --git a/zypp/ResPool.h b/zypp/ResPool.h index bbd9125..40938ff 100644 --- a/zypp/ResPool.h +++ b/zypp/ResPool.h @@ -124,7 +124,7 @@ namespace zypp { return make_filter_end( filter_r, *this ); } template - Iterable> filter( const _Filter & filter_r ) const + Iterable > filter( const _Filter & filter_r ) const { return makeIterable( filterBegin( filter_r ), filterEnd( filter_r ) ); } //@} @@ -153,7 +153,7 @@ namespace zypp filter_iterator byStatusEnd( const filter::ByStatus & filter_r ) const { return make_filter_end( filter_r, *this ); } - Iterable> byStatus( const filter::ByStatus & filter_r ) const + Iterable > byStatus( const filter::ByStatus & filter_r ) const { return makeIterable( byStatusBegin( filter_r ), byStatusEnd( filter_r ) ); } //@} diff --git a/zypp/pool/PoolImpl.h b/zypp/pool/PoolImpl.h index 338e240..24249bc 100644 --- a/zypp/pool/PoolImpl.h +++ b/zypp/pool/PoolImpl.h @@ -179,9 +179,9 @@ namespace zypp public: /** \name Save and restore state. */ //@{ - void SaveState( const ResObject::Kind & kind_r ); + void SaveState( const ResKind & kind_r ); - void RestoreState( const ResObject::Kind & kind_r ); + void RestoreState( const ResKind & kind_r ); //@} /////////////////////////////////////////////////////////////////// diff --git a/zypp/sat/SolvableType.h b/zypp/sat/SolvableType.h index ab47dfe..a84c76c 100644 --- a/zypp/sat/SolvableType.h +++ b/zypp/sat/SolvableType.h @@ -139,10 +139,12 @@ namespace zypp protected: SolvableType() {} - SolvableType( SolvableType && ) {} SolvableType( const SolvableType & ) {} - void operator=( SolvableType && ) {} void operator=( const SolvableType & ) {} +#ifndef SWIG + SolvableType( SolvableType && ) {} + void operator=( SolvableType && ) {} +#endif ~SolvableType() {} }; diff --git a/zypp/target/TargetImpl.cc b/zypp/target/TargetImpl.cc index 9492220..a2e232b 100644 --- a/zypp/target/TargetImpl.cc +++ b/zypp/target/TargetImpl.cc @@ -1518,6 +1518,8 @@ namespace zypp ZYppCommitResult::TransactionStepList & steps( result_r.rTransactionStepList() ); MIL << "TargetImpl::commit(" << policy_r << ")" << steps.size() << endl; + HistoryLog().stampCommand(); + bool abort = false; RpmPostTransCollector postTransCollector( _root ); std::vector successfullyInstalledPackages; diff --git a/zypp/ui/SelFilters.h b/zypp/ui/SelFilters.h index 2fcdfc7..0b629ad 100644 --- a/zypp/ui/SelFilters.h +++ b/zypp/ui/SelFilters.h @@ -32,7 +32,7 @@ namespace zypp /** */ struct ByKind : public SelectableFilterFunctor { - ByKind( const ResObject::Kind & kind_r ) + ByKind( const ResKind & kind_r ) : _kind( kind_r ) {} @@ -41,7 +41,7 @@ namespace zypp return obj && obj->kind() == _kind; } - ResObject::Kind _kind; + ResKind _kind; }; /** */ diff --git a/zypp/ui/Selectable.cc b/zypp/ui/Selectable.cc index 6c87fc1..e8678e8 100644 --- a/zypp/ui/Selectable.cc +++ b/zypp/ui/Selectable.cc @@ -55,7 +55,7 @@ namespace zypp IdString Selectable::ident() const { return _pimpl->ident(); } - ResObject::Kind Selectable::kind() const + ResKind Selectable::kind() const { return _pimpl->kind(); } const std::string & Selectable::name() const diff --git a/zypp/ui/Selectable.h b/zypp/ui/Selectable.h index 285c3f1..4119326 100644 --- a/zypp/ui/Selectable.h +++ b/zypp/ui/Selectable.h @@ -114,7 +114,7 @@ namespace zypp IdString ident() const; /** The ResObjects kind. */ - ResObject::Kind kind() const; + ResKind kind() const; /** The ResObjects name. */ const std::string & name() const; diff --git a/zypp/ui/SelectableImpl.h b/zypp/ui/SelectableImpl.h index 7346dda..b37322a 100644 --- a/zypp/ui/SelectableImpl.h +++ b/zypp/ui/SelectableImpl.h @@ -57,7 +57,7 @@ namespace zypp public: template - Impl( const ResObject::Kind & kind_r, + Impl( const ResKind & kind_r, const std::string & name_r, _Iterator begin_r, _Iterator end_r ) @@ -80,7 +80,7 @@ namespace zypp { return _ident; } /** */ - ResObject::Kind kind() const + ResKind kind() const { return _kind; } /** */ @@ -428,7 +428,7 @@ namespace zypp private: const IdString _ident; - const ResObject::Kind _kind; + const ResKind _kind; const std::string _name; InstalledItemSet _installedItems; AvailableItemSet _availableItems;