store patch function. tree structure is auto created
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Wed, 11 Jan 2006 12:59:29 +0000 (12:59 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Wed, 11 Jan 2006 12:59:29 +0000 (12:59 +0000)
devel/devel.dmacvicar/Makefile
devel/devel.dmacvicar/Makefile.am
devel/devel.dmacvicar/test2.cc

index 33ef402..25484bf 100644 (file)
@@ -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)
index b87af65..1f15606 100644 (file)
@@ -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
 
 ## ##################################################
index 5c30fe4..d676e17 100644 (file)
@@ -3,10 +3,13 @@
 #include <iostream>
 #include <fstream>
 #include <sstream>
+#include <streambuf>
 
 #include "boost/filesystem/operations.hpp" // includes boost/filesystem/path.hpp
 #include "boost/filesystem/fstream.hpp"    // ditto
 
+#include <boost/iostreams/device/file_descriptor.hpp>
+
 #include "dbxml/DbXml.hpp"
 
 #include <zypp/base/Logger.h>
@@ -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<Patch::Ptr> installedPatches()
+  std::list<Patch::Ptr> installedPatches() const
   {
     return list<Patch::Ptr>();
   }
 
   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;       
 }