From: Duncan Mac-Vicar P Date: Thu, 10 Aug 2006 13:02:44 +0000 (+0000) Subject: - Support for plaindir sources. X-Git-Tag: BASE-SuSE-SLE-10-SP2-Branch~493 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=17749206d4b3e9018654e71cb2d08f4260efed33;p=platform%2Fupstream%2Flibzypp.git - Support for plaindir sources. pending fixes: - delay metadata read till resolvables() ? not sure yet - location seems to be broken as the path is appended twice. --- diff --git a/devel/devel.dmacvicar/Makefile.am b/devel/devel.dmacvicar/Makefile.am index ff4bdba..3ab3bbe 100644 --- a/devel/devel.dmacvicar/Makefile.am +++ b/devel/devel.dmacvicar/Makefile.am @@ -11,7 +11,7 @@ AM_LDFLAGS = AM_CXXFLAGS = # gperf: -pg -LDADD = -L$(top_srcdir)/zypp/.libs -L$(top_srcdir)/zypp2/.libs -lzypp -lzypp2 -lboost_regex -lxml2 -lz +LDADD = -L$(top_srcdir)/zypp/.libs -L$(top_srcdir)/zypp2/.libs -lzypp -lzypp2 -lboost_regex -lxml2 -lz $(top_srcdir)/testsuite/src/utils/lib@PACKAGE@_testsuite_utils.la ## ################################################## diff --git a/devel/devel.dmacvicar/mediaset.cc b/devel/devel.dmacvicar/mediaset.cc new file mode 100644 index 0000000..a4e2d75 --- /dev/null +++ b/devel/devel.dmacvicar/mediaset.cc @@ -0,0 +1,71 @@ +#include +#include +#include +#include + +#include "boost/filesystem/operations.hpp" // includes boost/filesystem/path.hpp +#include "boost/filesystem/fstream.hpp" // ditto + +#include + +#include +#include +#include +#include +#include +/////////////////////////////////////////////////////////////////// + +#include + + +#include +#include + +#include "zypp/CapFactory.h" +#include "zypp/KeyRing.h" +#include "zypp/Product.h" +#include "zypp/Selection.h" +#include "zypp/PublicKey.h" + +#include "zypp/ZYppFactory.h" + +#include "zypp/MediaSetAccess.h" +#include "zypp2/source/yum/YUMSourceCacher.h" + +using namespace zypp::detail; + +using namespace std; +using namespace zypp; +using namespace zypp::source; +//using namespace DbXml; + +#define TestKind Selection + +int main() +{ + //MediaSetAccess ma( Url("cd:///"), Pathname("/")); + //MIL << "done 1" << std::endl; + //ChecksumFileChecker checker(CheckSum("sha1", "fa0abb22f703a3a41f7a39f0844b24daf572fd4c")); + //Pathname local = ma.provideFile("content", 1, checker); + //MIL << local << std::endl; + try + { + //zypp::source::yum::YUMSourceCacher cacher(Pathname("/")); + //cacher.cache( Url("dir:/space/tmp/factory-yum"), Pathname("/")); + ZYpp::Ptr z = getZYpp(); + z->initializeTarget("/"); + + for (ResStore::resfilter_const_iterator it = z->target()->byKindBegin(ResTraits::kind); it != z->target()->byKindEnd(ResTraits::kind); ++it) + { + zypp::TestKind::constPtr res = asKind( *it ); + MIL << res->name() << " " << res->edition() << std::endl; + } + + } + catch ( const Exception &e ) + { + MIL << "Sorry, bye" << endl; + } +} + + diff --git a/devel/devel.dmacvicar/target_iterate_by_kind.cc b/devel/devel.dmacvicar/target_iterate_by_kind.cc new file mode 100644 index 0000000..a4e2d75 --- /dev/null +++ b/devel/devel.dmacvicar/target_iterate_by_kind.cc @@ -0,0 +1,71 @@ +#include +#include +#include +#include + +#include "boost/filesystem/operations.hpp" // includes boost/filesystem/path.hpp +#include "boost/filesystem/fstream.hpp" // ditto + +#include + +#include +#include +#include +#include +#include +/////////////////////////////////////////////////////////////////// + +#include + + +#include +#include + +#include "zypp/CapFactory.h" +#include "zypp/KeyRing.h" +#include "zypp/Product.h" +#include "zypp/Selection.h" +#include "zypp/PublicKey.h" + +#include "zypp/ZYppFactory.h" + +#include "zypp/MediaSetAccess.h" +#include "zypp2/source/yum/YUMSourceCacher.h" + +using namespace zypp::detail; + +using namespace std; +using namespace zypp; +using namespace zypp::source; +//using namespace DbXml; + +#define TestKind Selection + +int main() +{ + //MediaSetAccess ma( Url("cd:///"), Pathname("/")); + //MIL << "done 1" << std::endl; + //ChecksumFileChecker checker(CheckSum("sha1", "fa0abb22f703a3a41f7a39f0844b24daf572fd4c")); + //Pathname local = ma.provideFile("content", 1, checker); + //MIL << local << std::endl; + try + { + //zypp::source::yum::YUMSourceCacher cacher(Pathname("/")); + //cacher.cache( Url("dir:/space/tmp/factory-yum"), Pathname("/")); + ZYpp::Ptr z = getZYpp(); + z->initializeTarget("/"); + + for (ResStore::resfilter_const_iterator it = z->target()->byKindBegin(ResTraits::kind); it != z->target()->byKindEnd(ResTraits::kind); ++it) + { + zypp::TestKind::constPtr res = asKind( *it ); + MIL << res->name() << " " << res->edition() << std::endl; + } + + } + catch ( const Exception &e ) + { + MIL << "Sorry, bye" << endl; + } +} + + diff --git a/devel/devel.dmacvicar/testbed.cc b/devel/devel.dmacvicar/testbed.cc index a4e2d75..b64e5e0 100644 --- a/devel/devel.dmacvicar/testbed.cc +++ b/devel/devel.dmacvicar/testbed.cc @@ -25,13 +25,17 @@ #include "zypp/KeyRing.h" #include "zypp/Product.h" #include "zypp/Selection.h" +#include "zypp/Package.h" #include "zypp/PublicKey.h" #include "zypp/ZYppFactory.h" #include "zypp/MediaSetAccess.h" +#include "zypp/SourceFactory.h" #include "zypp2/source/yum/YUMSourceCacher.h" +#include "testsuite/src/utils/TestUtils.h" + using namespace zypp::detail; using namespace std; @@ -43,23 +47,28 @@ using namespace zypp::source; int main() { - //MediaSetAccess ma( Url("cd:///"), Pathname("/")); - //MIL << "done 1" << std::endl; - //ChecksumFileChecker checker(CheckSum("sha1", "fa0abb22f703a3a41f7a39f0844b24daf572fd4c")); - //Pathname local = ma.provideFile("content", 1, checker); - //MIL << local << std::endl; try { - //zypp::source::yum::YUMSourceCacher cacher(Pathname("/")); - //cacher.cache( Url("dir:/space/tmp/factory-yum"), Pathname("/")); ZYpp::Ptr z = getZYpp(); z->initializeTarget("/"); - for (ResStore::resfilter_const_iterator it = z->target()->byKindBegin(ResTraits::kind); it != z->target()->byKindEnd(ResTraits::kind); ++it) + //SourceManager_Ptr manager = SourceManager::sourceManager(); + + Source_Ref source = SourceFactory().createFrom( Url("dir:/space/rpms/duncan/vim/i386"), "/", "bleh", Pathname() ); + ResStore store = source.resolvables(); + //zypp::testsuite::utils::dump(store, true, true); + + for (ResStore::const_iterator it = store.begin(); it != store.end(); ++it) + { + zypp::Package::Ptr res = asKind( *it ); + MIL << res->name() << " " << res->edition() << " " << res->location() << std::endl; + } + + /*for (ResStore::resfilter_const_iterator it = z->target()->byKindBegin(ResTraits::kind); it != z->target()->byKindEnd(ResTraits::kind); ++it) { zypp::TestKind::constPtr res = asKind( *it ); MIL << res->name() << " " << res->edition() << std::endl; - } + }*/ } catch ( const Exception &e ) @@ -69,3 +78,4 @@ int main() } + diff --git a/zypp/SourceFactory.cc b/zypp/SourceFactory.cc index 0900132..4673d2e 100644 --- a/zypp/SourceFactory.cc +++ b/zypp/SourceFactory.cc @@ -191,26 +191,28 @@ namespace zypp MIL << "Not SUSE tags source, trying next type" << endl; } -#warning Plaindir disabled in autoprobing -#if 0 try + { + if ( ! ( ( url_r.getScheme() == "file") || ( url_r.getScheme() == "dir ") ) ) { MIL << "Trying the Plaindir source" << endl; Source_Ref::Impl_Ptr impl( base_source - ? Impl::createBaseSourceImpl(id, path_r, alias_r, cache_dir_r) - : Impl::createSourceImpl(id, path_r, alias_r, cache_dir_r) ); - MIL << "Found the Plaindir source" << endl; - + ? Impl::createBaseSourceImpl(id, path_r, alias_r, cache_dir_r, auto_refresh) + : Impl::createSourceImpl(id, path_r, alias_r, cache_dir_r, auto_refresh) ); + MIL << "Using the Plaindir source" << endl; report->endProbe (url_r); - return Source_Ref(impl); } + else + { + ZYPP_THROW(Exception("Url scheme " + url_r.getScheme() + " not compatible with plaindir sources. Only local paths supported")); + } + } catch (const Exception & excpt_r) { ZYPP_CAUGHT(excpt_r); MIL << "Not Plaindir source, trying next type" << endl; } -#endif report->endProbe (url_r); diff --git a/zypp/source/plaindir/PlaindirImpl.cc b/zypp/source/plaindir/PlaindirImpl.cc index 23df354..c533311 100644 --- a/zypp/source/plaindir/PlaindirImpl.cc +++ b/zypp/source/plaindir/PlaindirImpl.cc @@ -6,52 +6,120 @@ | /_____||_| |_| |_| | | | \---------------------------------------------------------------------*/ -/** \file zypp/source/plaindir/PlaindirImpl.cc - * -*/ + #include #include "zypp/base/Logger.h" #include "zypp/source/plaindir/PlaindirImpl.h" using std::endl; +using namespace std; /////////////////////////////////////////////////////////////////// namespace zypp { ///////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////// - namespace source - { ///////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////// - namespace plaindir - { ///////////////////////////////////////////////////////////////// - - /////////////////////////////////////////////////////////////////// - // - // METHOD NAME : PlaindirImpl::PlaindirImpl - // METHOD TYPE : Ctor - // - PlaindirImpl::PlaindirImpl() - {} - - /////////////////////////////////////////////////////////////////// - // - // METHOD NAME : PlaindirImpl::~PlaindirImpl - // METHOD TYPE : Dtor - // - PlaindirImpl::~PlaindirImpl() - {} - - /////////////////////////////////////////////////////////////////// - // - // METHOD NAME : PlaindirImpl::~PlaindirImpl - // METHOD TYPE : Dtor - // - void PlaindirImpl::factoryInit() - { - ZYPP_THROW( Exception( "Plaindir not implemented!" ) ); - } +/////////////////////////////////////////////////////////////////// +namespace source +{ ///////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// +namespace plaindir +{ ///////////////////////////////////////////////////////////////// + +PlaindirImpl::PlaindirImpl() +{ + +} + +PlaindirImpl::~PlaindirImpl() +{ + +} + + +void PlaindirImpl::factoryInit() +{ + if ( ! ( (url().getScheme() == "file") || (url().getScheme() == "dir") ) ) + { + ZYPP_THROW( Exception( "Plaindir only supports local paths, scheme [" + url().getScheme() + "] is not local" ) ); + } + + Pathname thePath = Pathname(url().getPathName()) + path(); + MIL << "Going to read dir " << thePath << std::endl; + + extract_packages_from_directory( _store, thePath, selfSourceRef(), true ); + MIL << "Plaindir source initialized." << std::endl; + MIL << " Url : " << url() << std::endl; + MIL << " Path : " << path() << std::endl; +} + +int PlaindirImpl::extract_packages_from_directory (ResStore & store, const Pathname & path, Source_Ref source, bool recursive) +{ + Pathname filename; + PathInfo magic; + bool distro_magic, pkginfo_magic; + + DBG << "extract_packages_from_directory(.., " << path << ", " << source.alias() << ", " << recursive << ")" << endl; + + /* + Check for magic files that indicate how to treat the + directory. The files aren't read -- it is sufficient that + they exist. + */ + magic = PathInfo( path + "/RC_SKIP" ); + if (magic.isExist()) { + return 0; + } + + magic = PathInfo( path + "/RC_RECURSIVE" ); + if (magic.isExist()) + recursive = true; + + magic = PathInfo( path + "/RC_BY_DISTRO" ); + distro_magic = magic.isExist(); + + pkginfo_magic = true; + magic = PathInfo( path + "/RC_IGNORE_PKGINFO" ); + if (magic.isExist()) + pkginfo_magic = false; + + + std::list dircontent; + if (filesystem::readdir( dircontent, path, false) != 0) { // dont look for dot files + ERR << "readdir " << path << " failed" << endl; + return -1; + } + + for (std::list::const_iterator it = dircontent.begin(); it != dircontent.end(); ++it) { + Pathname file_path = path + *it; + PathInfo file_info( file_path ); + if (recursive && file_info.isDir()) { + + extract_packages_from_directory( store, file_path, source, recursive ); + + } else if (file_info.isFile()) { + + string::size_type dotpos = it->find_last_of("."); + if (dotpos == string::npos) + continue; + if (string(*it, ++dotpos) != "rpm") + continue; + target::rpm::RpmHeader::constPtr header = target::rpm::RpmHeader::readPackage( file_path ); + Package::Ptr package = target::rpm::RpmDb::makePackageFromHeader( header, NULL, file_path, source ); + + if (package != NULL) { + DBG << "Adding package " << *package << endl; + store.insert( package ); + } + } + } + return 0; +} + + + + + ///////////////////////////////////////////////////////////////// } // namespace plaindir /////////////////////////////////////////////////////////////////// diff --git a/zypp/source/plaindir/PlaindirImpl.h b/zypp/source/plaindir/PlaindirImpl.h index e33e4c4..783b59d 100644 --- a/zypp/source/plaindir/PlaindirImpl.h +++ b/zypp/source/plaindir/PlaindirImpl.h @@ -14,6 +14,9 @@ #include +#include +#include + #include "zypp/source/SourceImpl.h" /////////////////////////////////////////////////////////////////// @@ -58,6 +61,7 @@ namespace zypp * \throw EXCEPTION on fail */ virtual void factoryInit(); + int extract_packages_from_directory (ResStore & store, const Pathname & path, Source_Ref source, bool recursive); }; ///////////////////////////////////////////////////////////////////