From: Michael Andres Date: Tue, 17 Jan 2006 01:25:16 +0000 (+0000) Subject: - fixed bug in PathInfo X-Git-Tag: BASE-SuSE-SLE-10-SP2-Branch~3319 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e565355797fcb4852a1bf87f992a8ecc6b1cb778;p=platform%2Fupstream%2Flibzypp.git - fixed bug in PathInfo - prepared SuseTagsImpl (formerly UnitedLinux source) Still a fake, jusst able to evaluate a packages file. - Added query to ResStore and provide some basic query functors. Probabely needs some more documentation. --- diff --git a/devel/devel.ma/Main.cc b/devel/devel.ma/Main.cc index bb15f11..0cd800f 100644 --- a/devel/devel.ma/Main.cc +++ b/devel/devel.ma/Main.cc @@ -4,47 +4,50 @@ #include #include -#include -#include +#include +#include +#include + +#include +#include +#include +#include + +#include using namespace std; using namespace zypp; -template - void allCompare( const Edition & lhs, const Edition & rhs, - _Compare compare ) - { - MIL << "===============" << endl; -#define CMP(O) DBG << compare(lhs,rhs) << '\t' << lhs << '\t' << Rel::O << '\t' << rhs << "\t==> " << compareByRel( Rel::O, lhs, rhs, compare ) << endl - CMP( NONE ); - CMP( ANY ); - CMP( LT ); - CMP( LE ); - CMP( EQ ); - CMP( GE ); - CMP( GT ); - CMP( NE ); -#undef CMP - } +/////////////////////////////////////////////////////////////////// + +bool all( const ResObject::Ptr & ) +{ return true; } + +bool doPrintM( const ResObject::Ptr & p ) +{ + MIL << *p << endl; + return true; +} +bool doPrint( const ResObject::Ptr & p ) +{ + DBG << *p << endl; + return true; +} -template - void allRange( const Edition & lhs, const Edition & rhs) +struct Print +{ + Print( const std::string & name_r ) + : _name( name_r ) + {} + std::string _name; + bool operator()( ResObject::Ptr p ) const { - typedef Range Range; - - MIL << "===============" << endl; -#define CMP(L,R) DBG << Rel::L<<' '<( l, r ); - allRange( l, r ); - -#if 0 - Edition::Range any; - DBG << any << endl; - - Edition l( "1.0" ); - Edition r( "2.0" ); - -#define R(O,E) Edition::Range( Rel::O, E ) - -#define NONE(E) R(NONE,E) -#define ANY(E) R(ANY,E) -#define LT(E) R(LT,E) -#define LE(E) R(LE,E) -#define EQ(E) R(EQ,E) -#define GE(E) R(GE,E) -#define GT(E) R(GT,E) -#define NE(E) R(NE,E) - -#define OV(L,R) DBG << #L << " <> " << #R << " ==> " << Edition::Range::overlaps( L, R ) << endl - - ERR << "Omitting Rel::NE" << endl; - -#define OVALL( L ) \ - DBG << "----------------------------" << endl; \ - OV( L, NONE(r) ); \ - OV( L, ANY(r) ); \ - OV( L, LT(r) ); \ - OV( L, LE(r) ); \ - OV( L, EQ(r) ); \ - OV( L, GE(r) ); \ - OV( L, GT(r) ); \ - DBG << "----------------------------" << endl; - - OVALL( NONE(l) ); - OVALL( ANY(l) ); - OVALL( LT(l) ); - OVALL( LE(l) ); - OVALL( EQ(l) ); - OVALL( GE(l) ); - OVALL( GT(l) ); - - // same for l > r and l == r -#endif + Pathname f( "./p" ); + Source src( SourceFactory().createFrom( new source::SuseTagsImpl( f ) ) ); + INT << src.resolvables().size() << endl; + + src.resolvables().forEach( chain( resfilter::ByKind( ResTraits::kind ), + resfilter::ByName( "rpm" ) + ), + resfilter::chain( Print("1"), + chain( resfilter::chain( Print("A"), resfilter::chain( Print("B"), Print("C") ) ), + Print("2") + ) + ) + ); + + + INT << "===[END]============================================" << endl; return 0; } diff --git a/devel/devel.ma/Parse.cc b/devel/devel.ma/Parse.cc index fecfe3b..02ff76e 100644 --- a/devel/devel.ma/Parse.cc +++ b/devel/devel.ma/Parse.cc @@ -5,11 +5,14 @@ #include #include -#include #include +#include #include -#include +#include + +//#include +//#include using std::endl; @@ -35,23 +38,10 @@ namespace zypp } }; //////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////// - namespace parser - { ///////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////// - namespace tagfile - { ///////////////////////////////////////////////////////////////// - - ///////////////////////////////////////////////////////////////// - } // namespace tagfile - /////////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////// - } // namespace parser - /////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// } // namespace zypp /////////////////////////////////////////////////////////////////// @@ -64,6 +54,79 @@ namespace zypp using namespace zypp; using namespace std; +//////////////////////////////////// + +struct ResFilter {}; +struct ResActor {}; + +/////////////////////////////////////////////////////////////////// + +template + struct Always + { + bool operator()( ResObject::Ptr ) const + { return _val; } + }; + +/////////////////////////////////////////////////////////////////// + + /** Filter by name. */ + template + struct ByNameFilter + { + ByNameFilter( const std::string & name_r, const _Function & fnc_r = _Function() ) + : _name( name_r ) + , _fnc( fnc_r ) + {} + + bool operator()( ResObject::Ptr p ) const + { + return ( p->name() == _name ) && _fnc( p ); + } + + std::string _name; + const _Function & _fnc; + }; + + /** Convenience creating appropriate ByNameFilter. */ + template + ByNameFilter<_Function> byName( const std::string & name_r, const _Function & fnc_r ) + { return ByNameFilter<_Function>( name_r, fnc_r ); } + + ByNameFilter > byName( const std::string & name_r ) + { return ByNameFilter >( name_r ); } + + +/////////////////////////////////////////////////////////////////// + +ResStore store; + +template + unsigned sforEach( _Filter filter_r, _Function fnc_r ) + { + unsigned cnt = 0; + for ( ResStore::const_iterator it = store.begin(); it != store.end(); ++it ) + { + if ( filter_r( *it ) ) + { + if ( fnc_r( *it ) ) + ++cnt; + else + break; + } + } + return cnt; + } + +template + unsigned sforEach( _Function fnc_r ) + { + return sforEach( Always(), fnc_r ); + } + +//////////////////////////////////////////////////////////////////////////// + + //////////////////////////////////////////////////////////////////////////// // // Main @@ -80,12 +143,16 @@ int main( int argc, char* argv[] ) { std::list result( source::susetags::parsePackages( infile ) ); SEC << result.size() << endl; + store.insert( result.begin(), result.end() ); + MIL << store.size() << endl; } catch( Exception & excpt ) { ZYPP_RETHROW( excpt ); } + INT << sforEach( byName("rpm"), Always() ) << endl; + INT << "===[END]============================================" << endl; return 0; } diff --git a/zypp/Makefile.am b/zypp/Makefile.am index 54c0ec0..127897c 100644 --- a/zypp/Makefile.am +++ b/zypp/Makefile.am @@ -29,6 +29,7 @@ pkginclude_HEADERS = NeedAType.h \ Resolvable.h \ ResTraits.h \ ResStore.h \ + ResFilters.h \ Package.h \ Pathname.h \ Selection.h \ diff --git a/zypp/PathInfo.h b/zypp/PathInfo.h index 3dbc546..3a32eb5 100644 --- a/zypp/PathInfo.h +++ b/zypp/PathInfo.h @@ -336,13 +336,13 @@ namespace zypp /** Returns current users permission ([0-7])*/ mode_t userMay() const; - bool userMayR() const { return( userMay() & 01 ); } + bool userMayR() const { return( userMay() & 04 ); } bool userMayW() const { return( userMay() & 02 ); } - bool userMayX() const { return( userMay() & 04 ); } + bool userMayX() const { return( userMay() & 01 ); } - bool userMayRW() const { return( (userMay() & 03) == 03 ); } + bool userMayRW() const { return( (userMay() & 06) == 06 ); } bool userMayRX() const { return( (userMay() & 05) == 05 ); } - bool userMayWX() const { return( (userMay() & 06) == 06 ); } + bool userMayWX() const { return( (userMay() & 03) == 03 ); } bool userMayRWX() const { return( userMay() == 07 ); } //@} diff --git a/zypp/ResFilters.h b/zypp/ResFilters.h new file mode 100644 index 0000000..393d7d9 --- /dev/null +++ b/zypp/ResFilters.h @@ -0,0 +1,139 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ +/** \file zypp/ResFilters.h + * +*/ +#ifndef ZYPP_RESFILTERS_H +#define ZYPP_RESFILTERS_H + +#include + +#include "zypp/Resolvable.h" + +/////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// + namespace resfilter + { ///////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////////// + // + // Predefined filters + // + /////////////////////////////////////////////////////////////////// + + struct True + { + bool operator()( ResObject::Ptr ) const + { + return true; + } + }; + + True true_c() + { return True(); } + + /////////////////////////////////////////////////////////////////// + + struct False + { + bool operator()( ResObject::Ptr ) const + { + return false; + } + }; + + False false_c() + { return False(); } + + /////////////////////////////////////////////////////////////////// + + template + struct Not + { + Not( _Condition cond_r ) + : _cond( cond_r ) + {} + bool operator()( ResObject::Ptr p ) const + { + return ! _cond( p ); + } + _Condition _cond; + }; + + template + Not<_Condition> not_c( _Condition cond_r ) + { + return Not<_Condition>( cond_r ); + } + + /////////////////////////////////////////////////////////////////// + + template + struct Chain + { + Chain( _ACondition conda_r, _BCondition condb_r ) + : _conda( conda_r ) + , _condb( condb_r ) + {} + bool operator()( ResObject::Ptr p ) const + { + return _conda( p ) && _condb( p ); + } + _ACondition _conda; + _BCondition _condb; + }; + + template + Chain<_ACondition, _BCondition> chain( _ACondition conda_r, _BCondition condb_r ) + { + return Chain<_ACondition, _BCondition>( conda_r, condb_r ); + } + + /////////////////////////////////////////////////////////////////// + // + // Now some Resolvable attributes + // + /////////////////////////////////////////////////////////////////// + + struct ByKind + { + ByKind( const ResObject::Kind & kind_r ) + : _kind( kind_r ) + {} + bool operator()( ResObject::Ptr p ) const + { + return p->kind() == _kind; + } + ResObject::Kind _kind; + }; + + struct ByName + { + ByName( const std::string & name_r ) + : _name( name_r ) + {} + bool operator()( ResObject::Ptr p ) const + { + return p->name() == _name; + } + std::string _name; + }; + + + /////////////////////////////////////////////////////////////////// + + ///////////////////////////////////////////////////////////////// + } // namespace resfilter + /////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////// +} // namespace zypp +/////////////////////////////////////////////////////////////////// +#endif // ZYPP_RESFILTERS_H diff --git a/zypp/ResStore.h b/zypp/ResStore.h index f3d9ad5..4abbef1 100644 --- a/zypp/ResStore.h +++ b/zypp/ResStore.h @@ -89,14 +89,49 @@ namespace zypp void clear() { store().clear(); } - // query - template - _Function forEach( _Function fnc_r ) - { return std::for_each( store().begin(), store().end(), fnc_r ); } + /** Query inerface. + * Both, \a filter_r and \a fnc_r are expected to be + * functions or functors taking a ResObject::Ptr<\tt> + * as argument and return a \c bool. + * + * forEach iterates over all ResObjects and invokes \a fnc_r, + * iff \a filter_r returned \c true. If \a fnc_r returnes + * \c false the loop is aborted. + * + * forEach returns the number of \a fnc_r invocations. Positive + * if the loop succeeded. Negative if some call to \a fnc_r + * returned \c false. + + + * \see ResFilters for a collection of predefined filters. + */ + template + int forEach( _Filter filter_r, _Function fnc_r ) const + { + int cnt = 0; + for ( ResStore::const_iterator it = _store.begin(); it != _store.end(); ++it ) + { + if ( filter_r( *it ) ) + { + ++cnt; + if ( ! fnc_r( *it ) ) + return -cnt; + } + } + return cnt; + } template - _Function forEach( _Function fnc_r ) const - { return std::for_each( store().begin(), store().end(), fnc_r ); } + int forEach( _Function fnc_r ) const + { + int cnt = 0; + for ( ResStore::const_iterator it = _store.begin(); it != _store.end(); ++it ) + { + ++cnt; + if ( ! fnc_r( *it ) ) + return -cnt; + } + return cnt; + } private: /** */ @@ -117,69 +152,6 @@ namespace zypp /** \relates ResStore Stream output */ std::ostream & operator<<( std::ostream & str, const ResStore & obj ); - /////////////////////////////////////////////////////////////////// - // - // Predefined filters - // - /////////////////////////////////////////////////////////////////// - - /** Filter by kind. */ - template - struct ByKindFilter - { - ByKindFilter( const ResObject::Kind & kind_r, const _Function & fnc_r ) - : _kind( kind_r ) - , _fnc( fnc_r ) - {} - - void operator()( ResObject::Ptr p ) const - { - if ( p->kind() == _kind ) - _fnc( p ); - } - - ResObject::Kind _kind; - const _Function & _fnc; - }; - - /** Convenience creating appropriate ByKindFilter. */ - template - ByKindFilter<_Function> byKind( const ResObject::Kind & kind_r, const _Function & fnc_r ) - { return ByKindFilter<_Function>( kind_r, fnc_r ); } - - /** Convenience creating appropriate ByKindFilter. */ - template - ByKindFilter<_Function> byKind( const _Function & fnc_r ) - { return ByKindFilter<_Function>( ResTraits<_Res>::kind, fnc_r ); } - - /////////////////////////////////////////////////////////////////// - - /** Filter by name. */ - template - struct ByNameFilter - { - ByNameFilter( const std::string & name_r, const _Function & fnc_r ) - : _name( name_r ) - , _fnc( fnc_r ) - {} - - void operator()( ResObject::Ptr p ) const - { - if ( p->name() == _name ) - _fnc( p ); - } - - std::string _name; - const _Function & _fnc; - }; - - /** Convenience creating appropriate ByNameFilter. */ - template - ByNameFilter<_Function> byName( const std::string & name_r, const _Function & fnc_r ) - { return ByNameFilter<_Function>( name_r, fnc_r ); } - - /////////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////// } // namespace zypp /////////////////////////////////////////////////////////////////// diff --git a/zypp/Source.h b/zypp/Source.h index 9b36a37..6a4c88e 100644 --- a/zypp/Source.h +++ b/zypp/Source.h @@ -57,7 +57,7 @@ namespace zypp /** Stream output. */ std::ostream & dumpOn( std::ostream & str ) const; - public: + private: /** Pointer to implementation */ RW_pointer > _pimpl; }; diff --git a/zypp/source/Builtin.h b/zypp/source/Builtin.h index 9287b51..c954c7a 100644 --- a/zypp/source/Builtin.h +++ b/zypp/source/Builtin.h @@ -16,6 +16,7 @@ #include #include "zypp/source/SourceImpl.h" +#include "zypp/source/susetags/SuseTagsImpl.h" #include "zypp/source/yum/YUMSource.h" /////////////////////////////////////////////////////////////////// diff --git a/zypp/source/susetags/Makefile.am b/zypp/source/susetags/Makefile.am index 69940b7..12fc49c 100644 --- a/zypp/source/susetags/Makefile.am +++ b/zypp/source/susetags/Makefile.am @@ -8,14 +8,16 @@ SUBDIRS = sourceincludedir = $(pkgincludedir)/source sourceinclude_HEADERS = \ - PackagesParser.h + PackagesParser.h\ + SuseTagsImpl.h noinst_LTLIBRARIES = lib@PACKAGE@_source_susetags.la ## ################################################## lib@PACKAGE@_source_susetags_la_SOURCES = \ - PackagesParser.cc + PackagesParser.cc \ + SuseTagsImpl.cc lib@PACKAGE@_source_susetags_la_LIBADD = diff --git a/zypp/source/susetags/PackagesParser.cc b/zypp/source/susetags/PackagesParser.cc index 09ab159..a09b7fc 100644 --- a/zypp/source/susetags/PackagesParser.cc +++ b/zypp/source/susetags/PackagesParser.cc @@ -80,7 +80,7 @@ namespace zypp ZYPP_THROW( ParseException( "Pkg" ) ); newPkg(); - nvrad = NVRAD( words[0], Edition(words[1],words[2]), Arch(words[4]) ); + nvrad = NVRAD( words[0], Edition(words[1],words[2]), Arch(words[3]) ); } } diff --git a/zypp/source/susetags/SuseTagsImpl.cc b/zypp/source/susetags/SuseTagsImpl.cc new file mode 100644 index 0000000..54a24f8 --- /dev/null +++ b/zypp/source/susetags/SuseTagsImpl.cc @@ -0,0 +1,81 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ +/** \file zypp/source/susetags/SuseTagsImpl.cc + * +*/ +#include +#include "zypp/base/Logger.h" +#include "zypp/base/Exception.h" + +#include "zypp/PathInfo.h" + +#include "zypp/source/susetags/SuseTagsImpl.h" +#include "zypp/source/susetags/PackagesParser.h" + +using std::endl; + +/////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// + namespace source + { ///////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// + namespace susetags + { ///////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////////// + // + // METHOD NAME : SuseTagsImpl::SuseTagsImpl + // METHOD TYPE : Ctor + // + SuseTagsImpl::SuseTagsImpl( const Pathname & localDir_r ) + { + PathInfo p( localDir_r ); + if ( p.isDir() ) + p( localDir_r + "packages" ); + if ( ! p.isFile() ) + ZYPP_THROW( Exception( p.asString()+" is not a file" ) ); + if ( ! p.userMayR() ) + ZYPP_THROW( Exception( p.asString()+" no permission to read" ) ); + + DBG << "Going to parse " << p << endl; + std::list content( parsePackages( p.path() ) ); + _store.insert( content.begin(), content.end() ); + DBG << "SuseTagsImpl (fake) from " << p.path() << ": " + << content.size() << " packages" << endl; + } + + /////////////////////////////////////////////////////////////////// + // + // METHOD NAME : SuseTagsImpl::~SuseTagsImpl + // METHOD TYPE : Dtor + // + SuseTagsImpl::~SuseTagsImpl() + {} + + /////////////////////////////////////////////////////////////////// + // + // METHOD NAME : SuseTagsImpl::dumpOn + // METHOD TYPE : std::ostream & + // + std::ostream & SuseTagsImpl::dumpOn( std::ostream & str ) const + { + return str << "SuseTagsImpl"; + } + + ///////////////////////////////////////////////////////////////// + } // namespace susetags + /////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////// + } // namespace source + /////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////// +} // namespace zypp +/////////////////////////////////////////////////////////////////// diff --git a/zypp/source/susetags/SuseTagsImpl.h b/zypp/source/susetags/SuseTagsImpl.h new file mode 100644 index 0000000..7fee0c4 --- /dev/null +++ b/zypp/source/susetags/SuseTagsImpl.h @@ -0,0 +1,66 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ +/** \file zypp/source/susetags/SuseTagsImpl.h + * +*/ +#ifndef ZYPP_SOURCE_SUSETAGS_SUSETAGSIMPL_H +#define ZYPP_SOURCE_SUSETAGS_SUSETAGSIMPL_H + +#include + +#include "zypp/Pathname.h" +#include "zypp/source/SourceImpl.h" + +/////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// + namespace source + { ///////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// + namespace susetags + { ///////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////////// + // + // CLASS NAME : SuseTagsImpl + // + /** */ + class SuseTagsImpl : public SourceImpl + { + public: + /** \deprecated Interim ctor + * \throw EXCEPTION on parse error + */ + SuseTagsImpl( const Pathname & localDir_r ); + /** Dtor */ + ~SuseTagsImpl(); + + public: + /** Stream output. */ + virtual std::ostream & dumpOn( std::ostream & str ) const; + + public: + + }; + /////////////////////////////////////////////////////////////////// + + ///////////////////////////////////////////////////////////////// + } // namespace susetags + /////////////////////////////////////////////////////////////////// + + using susetags::SuseTagsImpl; + + ///////////////////////////////////////////////////////////////// + } // namespace source + /////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////// +} // namespace zypp +/////////////////////////////////////////////////////////////////// +#endif // ZYPP_SOURCE_SUSETAGS_SUSETAGSIMPL_H diff --git a/zypp/source/susetags/SuseTagsImpl.lo b/zypp/source/susetags/SuseTagsImpl.lo new file mode 100644 index 0000000..e049aa4 --- /dev/null +++ b/zypp/source/susetags/SuseTagsImpl.lo @@ -0,0 +1,12 @@ +# SuseTagsImpl.lo - a libtool object file +# Generated by ltmain.sh - GNU libtool 1.5.14 (1.1220.2.195 2005/02/12 12:12:33) +# +# Please DO NOT delete this file! +# It is necessary for linking the library. + +# Name of the PIC object. +pic_object='.libs/SuseTagsImpl.o' + +# Name of the non-PIC object. +non_pic_object=none +