From: Duncan Mac-Vicar P Date: Wed, 11 Jan 2006 12:59:29 +0000 (+0000) Subject: store patch function. tree structure is auto created X-Git-Tag: BASE-SuSE-SLE-10-SP2-Branch~3430 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=caf4a9785d5a9341fbced0157840c7b3e923a783;p=platform%2Fupstream%2Flibzypp.git store patch function. tree structure is auto created --- diff --git a/devel/devel.dmacvicar/Makefile b/devel/devel.dmacvicar/Makefile index 33ef402..25484bf 100644 --- a/devel/devel.dmacvicar/Makefile +++ b/devel/devel.dmacvicar/Makefile @@ -192,7 +192,7 @@ AM_CXXFLAGS = # gperf: -pg # -ldbxml -lpathan -lxerces-c -lxquery -LDADD = $(top_srcdir)/zypp/libzypp.la -lboost_regex -ldb -ldb_cxx +LDADD = $(top_srcdir)/zypp/libzypp.la -lboost_regex -lboost_filesystem -ldb -ldb_cxx #LDADD = -lboost_regex -lsqlite3 -dbxml test2_SOURCES = test2.cc test2_debug_SOURCES = $(test2_SOURCES) diff --git a/devel/devel.dmacvicar/Makefile.am b/devel/devel.dmacvicar/Makefile.am index b87af65..1f15606 100644 --- a/devel/devel.dmacvicar/Makefile.am +++ b/devel/devel.dmacvicar/Makefile.am @@ -16,7 +16,7 @@ AM_CXXFLAGS = # -ldbxml -lpathan -lxerces-c -lxquery -LDADD = $(top_srcdir)/zypp/lib@PACKAGE@.la -lboost_regex -ldb -ldb_cxx +LDADD = $(top_srcdir)/zypp/lib@PACKAGE@.la -lboost_regex -lboost_filesystem -ldb -ldb_cxx #LDADD = -lboost_regex -lsqlite3 -dbxml ## ################################################## diff --git a/devel/devel.dmacvicar/test2.cc b/devel/devel.dmacvicar/test2.cc index 5c30fe4..d676e17 100644 --- a/devel/devel.dmacvicar/test2.cc +++ b/devel/devel.dmacvicar/test2.cc @@ -3,10 +3,13 @@ #include #include #include +#include #include "boost/filesystem/operations.hpp" // includes boost/filesystem/path.hpp #include "boost/filesystem/fstream.hpp" // ditto +#include + #include "dbxml/DbXml.hpp" #include @@ -51,7 +54,7 @@ using namespace zypp::storage; using namespace boost::filesystem; // for ease of tutorial presentation; // a namespace alias is preferred in real code - +using namespace boost::iostreams; //using namespace DbXml; @@ -225,7 +228,7 @@ class StorageBackend : public base::ReferenceCounted, private base::NonCopyable virtual void storePatch( Patch::Ptr p ) = 0; }; -#define ZYPP_DB_DIR path("./zypp_db") +#define ZYPP_DB_DIR "zypp_db" class TextBackend : public StorageBackend { @@ -240,14 +243,14 @@ class TextBackend : public StorageBackend initDirTree(); } - void initDirTree() + void initDirTree() const { // FIXME duncan * handle exceptions DBG << "Creating directory structure..." << std::endl; - create_directory( ZYPP_DB_DIR ); - create_directory( ZYPP_DB_DIR / path("patches") ); - create_directory( ZYPP_DB_DIR / path("selections") ); - create_directory( ZYPP_DB_DIR / path("products") ); + create_directory( path(ZYPP_DB_DIR) ); + create_directory( path(ZYPP_DB_DIR) / path("patches") ); + create_directory( path(ZYPP_DB_DIR) / path("selections") ); + create_directory( path(ZYPP_DB_DIR) / path("products") ); } TextBackend() @@ -259,26 +262,42 @@ class TextBackend : public StorageBackend { DBG << endl; } + + std::string randomFileName() const + { + FILE *fp; + char puffer[49]; + if ( (fp = popen("openssl rand -base64 48", "r")) == 0) + { + DBG << "mierda!" << std::endl; + //ZYPP_THROW("put some message here"); + } + + /*Ausgabe der von der Pipe gelesenen Daten*/ + fscanf(fp, "%s", &puffer); + pclose(fp); + return "blah"; + } + + std::string fileNameForPatch( Patch::Ptr patch ) const + { + return patch->id(); + } - std::list installedPatches() + std::list installedPatches() const { return list(); } void storePatch( Patch::Ptr p ) { - //ofstream file( "foobar/cheeze" ); - //file << "tastes good!\n"; - //file.close(); - //if ( !exists( "foobar/cheeze" ) ) - //std::cout << "Something is rotten in foobar\n"; - // Get a manager object. - //XmlManager myManager; - // Open a container - //XmlContainer myContainer = myManager.openContainer("zypp_db.dbxml"); - - DBG << std::endl; - DBG << std::endl << toXML(p) << std::endl; + std::string xml = toXML(p); + DBG << std::endl << xml << std::endl; + std::ofstream file; + // FIXME replace with path class of boost + file.open( (std::string(ZYPP_DB_DIR) + std::string("/patches/") + fileNameForPatch(p)).c_str() ); + file << xml; + file.close(); } private: //std::ostream & operator<<( std::ostream & str, const PatchYUMSerializer & obj ) @@ -313,6 +332,7 @@ class XMLBackend : public StorageBackend void storePatch( Patch::Ptr p ) { DBG << std::endl; + DBG << std::endl << toXML(p) << std::endl; } private: @@ -351,8 +371,9 @@ int main() if (iter.errorStatus()) throw *iter.errorStatus(); - XMLBackend backend; + TextBackend backend; backend.storePatch(patch1); + cout << backend.randomFileName() << std::endl; return 1; }