- Create the cache directly from the schema (installed) file.
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 12 Mar 2007 18:09:19 +0000 (18:09 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 12 Mar 2007 18:09:19 +0000 (18:09 +0000)
- move the code of SUSE tags downloader to its own source

devel/devel.dmacvicar/CMakeLists.txt
devel/devel.dmacvicar/SUSETagsDownloader.cc
doc/downloaders-mediaset.txt
zypp/CMakeLists.txt
zypp/MediaSetAccess.cc
zypp/MediaSetAccess.h
zypp/source/susetags/SUSETagsDownloader.cc [new file with mode: 0644]
zypp/source/susetags/SUSETagsDownloader.h [new file with mode: 0644]
zypp2/CMakeLists.txt
zypp2/cache/CacheInitializer.cpp

index 8284325..b110b36 100644 (file)
@@ -73,4 +73,6 @@ TARGET_LINK_LIBRARIES(scansource  zypp )
 ADD_EXECUTABLE(susetags-downloader SUSETagsDownloader.cc)
 TARGET_LINK_LIBRARIES(susetags-downloader  zypp )
 
-
+ADD_EXECUTABLE(cachestore CacheStore.cc)
+TARGET_LINK_LIBRARIES(cachestore  zypp )
+TARGET_LINK_LIBRARIES(cachestore  zypp2 )
\ No newline at end of file
index 992aed3..8842416 100644 (file)
@@ -14,7 +14,8 @@
 #include <zypp/media/MediaManager.h>
 #include <zypp/MediaSetAccess.h>
 #include <zypp/source/SUSEMediaVerifier.h>
-#include <zypp/nMediaLocation.h>
+#include <zypp/OnMediaLocation.h>
+#include <zypp/source/susetags/SUSETagsDownloader.h>
 #include <zypp/Fetcher.h>
 
 #include "zypp/Product.h"
 using namespace std;
 using namespace zypp;
 using namespace media;
-//using namespace source;
-
-class SUSETagsDownloader
-{
-  Url _url;
-  Pathname _path;
-  public:
-  SUSETagsDownloader( const Url &url, const Pathname &path )
-     : _url(url), _path(path)
-  {
-    
-  }
-
-  void download( const Pathname &dest_dir )
-  {
-    Fetcher fetcher(_url, _path);
-    fetcher.enqueue( OnMediaLocation().filename("/content") );
-    fetcher.start( dest_dir );
-    fetcher.reset();
-
-    std::ifstream file((dest_dir + "/content").asString().c_str());
-    std::string buffer;
-    Pathname descr_dir;
-
-    // Note this code assumes DESCR comes before as META
-
-    while (file && !file.eof())
-    {
-      getline(file, buffer);
-      if ( buffer.substr( 0, 5 ) == "DESCR" )
-      {
-        std::vector<std::string> words;
-        if ( str::split( buffer, std::back_inserter(words) ) != 2 )
-        {
-          // error
-          ZYPP_THROW(Exception("bad DESCR line")); 
-        }
-        descr_dir = words[1];
-      }
-      else if ( buffer.substr( 0, 4 ) == "META" )
-      {
-        std::vector<std::string> words;
-        if ( str::split( buffer, std::back_inserter(words) ) != 4 )
-        {
-          // error
-          ZYPP_THROW(Exception("bad DESCR line"));
-        }
-        OnMediaLocation location;
-        location.filename( descr_dir + words[3]).checksum( CheckSum( words[1], words[2] ) );
-        fetcher.enqueue(location);
-      }
-    }
-    file.close();
-    fetcher.start( dest_dir );
-  }
-};
-
+using namespace source::susetags;
 
 int main(int argc, char **argv)
 {
index e69de29..715e183 100644 (file)
@@ -0,0 +1,4 @@
+
+Downloaders and MediaSet
+========================
+dmacvicar@suse.de
index dd68fa8..18a06ee 100644 (file)
@@ -707,6 +707,7 @@ INSTALL(  FILES
 )
 
 SET( zypp_source_susetags_SRCS
+  source/susetags/SUSETagsDownloader.cc
   source/susetags/MediaMetadataParser.cc
   source/susetags/MediaPatchesMetadataParser.cc
   source/susetags/PackagesLangParser.cc
@@ -722,7 +723,8 @@ SET( zypp_source_susetags_SRCS
   source/susetags/SuseTagsSrcPackageImpl.cc
 )
 
-SET( zypp_source_susetags_HEADERS
+SET( zypp_source_susetags_HEADERS  
+  source/susetags/SUSETagsDownloader.h
   source/susetags/MediaMetadataParser.h
   source/susetags/MediaPatchesMetadataParser.h
   source/susetags/PackagesLangParser.h
index 2965d3f..29e80ac 100644 (file)
@@ -94,29 +94,6 @@ namespace zypp
 //       report->finish( file_url, source::DownloadFileReport::NO_ERROR, "" );
 //       return file;
 
-
-  void MediaSetAccess::providePossiblyCachedMetadataFile( const Pathname &file_to_download, unsigned medianr, const Pathname &destination, const Pathname &cached_file, const CheckSum &checksum )
-  {
-    Url file_url( _url.asString() + file_to_download.asString() );
-    // if we have a cached file and its the same
-    if ( PathInfo(cached_file).isExist() && (! checksum.empty()) && is_checksum( cached_file, checksum ) )
-    {
-      MIL << "file " << file_url << " found in previous cache. Using cached copy." << std::endl;
-      // checksum is already checked.
-      // we could later implement double failover and try to download if file copy fails.
-      if ( filesystem::copy(cached_file, destination) != 0 )
-        ZYPP_THROW(Exception("Can't copy " + cached_file.asString() + " to " + destination.asString()));
-    }
-    else
-    {
-      // we dont have it or its not the same, download it.
-      Pathname downloaded_file = provideFile( file_to_download, medianr, ChecksumFileChecker(checksum) );
-      
-      if ( filesystem::copy(downloaded_file, destination) != 0 )
-        ZYPP_THROW(Exception("Can't copy " + downloaded_file.asString() + " to " + destination.asString()));      
-    }
-  }
-
   Pathname MediaSetAccess::provideFile( const OnMediaLocation & on_media_file )
   {
     return provideFile( on_media_file.filename(), on_media_file.medianr() );
index df22293..edd096a 100644 (file)
@@ -66,27 +66,18 @@ namespace zypp
       ~MediaSetAccess();
 
       /**
-       * Sets a verifier for given media number
+       * Sets a \ref MediaVerifierRef verifier for given media number
        */
       void setVerifier( unsigned media_nr, media::MediaVerifierRef verifier );
       
       /**
-       * provide a file fom a multiple media
+       * provide a file from a media location.
        */
       Pathname provideFile( const OnMediaLocation & on_media_file );
 
-      /**
-       * provides a file on multiple media which is possibly cached
-       * The cached_file is provided and the Checksums are compared.
-       * if they match, the cached one is copied to the destination directory
-       * if not the file is provided and copied to the destination directory.
-       */
-      void providePossiblyCachedMetadataFile( const OnMediaLocation &file_on_media, const Pathname &destination, const Pathname &cached_file);
-
       Pathname provideFile(const Pathname & file, unsigned media_nr = 1 );
       Pathname provideFile(const Pathname & file, unsigned media_nr, const FileChecker checker );
-      void providePossiblyCachedMetadataFile( const Pathname &file_to_download, unsigned medianr, const Pathname &destination, const Pathname &cached_file, const CheckSum &checksum );
-
+      
     protected:
       Pathname provideFileInternal(const Pathname & file, unsigned media_nr, bool checkonly, bool cached);
       Url rewriteUrl (const Url & url_r, const media::MediaNr medianr);
diff --git a/zypp/source/susetags/SUSETagsDownloader.cc b/zypp/source/susetags/SUSETagsDownloader.cc
new file mode 100644 (file)
index 0000000..81838c5
--- /dev/null
@@ -0,0 +1,69 @@
+
+#include <fstream>
+#include "zypp/base/String.h"
+#include "zypp/OnMediaLocation.h"
+#include "zypp/Fetcher.h"
+
+#include "zypp/source/susetags/SUSETagsDownloader.h"
+
+using namespace std;
+
+namespace zypp
+{
+namespace source
+{
+namespace susetags
+{
+  
+SUSETagsDownloader::SUSETagsDownloader( const Url &url, const Pathname &path )
+    : _url(url), _path(path)
+{
+  
+}
+
+void SUSETagsDownloader::download( const Pathname &dest_dir )
+{
+  Fetcher fetcher(_url, _path);
+  fetcher.enqueue( OnMediaLocation().filename("/content") );
+  fetcher.start( dest_dir );
+  fetcher.reset();
+
+  std::ifstream file((dest_dir + "/content").asString().c_str());
+  std::string buffer;
+  Pathname descr_dir;
+
+  // Note this code assumes DESCR comes before as META
+
+  while (file && !file.eof())
+  {
+    getline(file, buffer);
+    if ( buffer.substr( 0, 5 ) == "DESCR" )
+    {
+      std::vector<std::string> words;
+      if ( str::split( buffer, std::back_inserter(words) ) != 2 )
+      {
+        // error
+        ZYPP_THROW(Exception("bad DESCR line")); 
+      }
+      descr_dir = words[1];
+    }
+    else if ( buffer.substr( 0, 4 ) == "META" )
+    {
+      std::vector<std::string> words;
+      if ( str::split( buffer, std::back_inserter(words) ) != 4 )
+      {
+        // error
+        ZYPP_THROW(Exception("bad DESCR line"));
+      }
+      OnMediaLocation location;
+      location.filename( descr_dir + words[3]).checksum( CheckSum( words[1], words[2] ) );
+      fetcher.enqueue(location);
+    }
+  }
+  file.close();
+  fetcher.start( dest_dir );
+}
+
+}// ns susetags
+}// ns source 
+} // ns zypp
\ No newline at end of file
diff --git a/zypp/source/susetags/SUSETagsDownloader.h b/zypp/source/susetags/SUSETagsDownloader.h
new file mode 100644 (file)
index 0000000..d070084
--- /dev/null
@@ -0,0 +1,37 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+
+#ifndef ZYPP_SOURCE_SUSETAGS_DOWNLOADER
+#define ZYPP_SOURCE_SUSETAGS_DOWNLOADER
+
+#include "zypp/Url.h"
+#include "zypp/Pathname.h"
+
+namespace zypp
+{
+  namespace source
+  {
+    namespace susetags
+    {
+  
+      class SUSETagsDownloader
+      {
+       public:
+        SUSETagsDownloader( const Url &url, const Pathname &path );
+        void download( const Pathname &dest_dir );
+       private:
+        Url _url;
+        Pathname _path;
+      };
+
+    } // ns susetags
+  } // ns source
+} // ns zypp
+
+#endif
\ No newline at end of file
index ff3dca2..b36c774 100644 (file)
@@ -128,3 +128,8 @@ TARGET_LINK_LIBRARIES(zypp2 ${CURL_LIBRARY} )
 TARGET_LINK_LIBRARIES(zypp2 ${LIBXML_LIBRARY} )
 TARGET_LINK_LIBRARIES(zypp2 ${SQLITE_LIBRARY} )
 TARGET_LINK_LIBRARIES(zypp2 ${ZLIB_LIBRARY} )
+
+# install DB schema
+# install XML schemas
+FILE( GLOB YUM_SCHEMA_FILES ${CMAKE_SOURCE_DIR}/zypp2/cache/schema/schema.sql )
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/zypp2/cache/schema/schema.sql DESTINATION "${CMAKE_INSTALL_PREFIX}/share/zypp/cache" )
index 9c18436..d8ddd93 100644 (file)
@@ -7,7 +7,10 @@
 |                                                                      |
 \---------------------------------------------------------------------*/
 
+#include <iostream>
 #include <vector>
+#include <sstream>
+#include <fstream>
 
 #include "zypp/base/Logger.h"
 #include "zypp/base/String.h"
@@ -37,8 +40,10 @@ CacheInitializer::CacheInitializer( const Pathname &root_r, const Pathname &db_f
   {
     _con.reset( new sqlite3_connection( (_root + db_file).asString().c_str()) );
   }
-  catch(exception &ex) {
-    ERR << "Exception Occured: " << ex.what() << endl;
+  catch(exception &ex)
+  {
+    ZYPP_RETHROW(Exception(ex.what()));
+    //ERR << "Exception Occured: " << ex.what() << endl;
   } 
 
   try
@@ -57,7 +62,8 @@ CacheInitializer::CacheInitializer( const Pathname &root_r, const Pathname &db_f
   }
   catch(exception &ex)
   {
-    ERR << "Exception Occured: " << ex.what() << endl;
+    ZYPP_RETHROW(Exception(ex.what()));
+    //ERR << "Exception Occured: " << ex.what() << endl;
   }
   
 }
@@ -80,16 +86,30 @@ bool CacheInitializer::tablesCreated() const
 
 void CacheInitializer::createTables()
 {
+  MIL << "Initializing cache schema..." << endl;
   sqlite3_transaction trans(*_con);
   {
-    char ** statements = getsql();
-    int i = 0;
-    while ( statements[i] != 0 )
+    string sql;
+    const char *filename = "/usr/share/zypp/cache/schema.sql";
+    std::ifstream stream(filename);
+    string buffer;
+    if ( stream )
+    {
+      stringstream str(sql);
+      while ( getline( stream, buffer ) )
+      {
+        sql += (buffer+"\n");
+      }
+      std::cout << sql << endl;
+    }
+    else
     {
-      ERR << "Executing " << statements[i] << endl;
-      _con->executenonquery(statements[i]);
-      i++;
+      ZYPP_THROW(Exception("Can't open db schema"));
     }
+    
+    //ERR << "Executing " << statements[i] << endl;
+    MIL << "Schema size: " << sql.size() << endl;
+    _con->execute(sql.c_str());
   }
   trans.commit();
 }