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
#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)
{
+
+Downloaders and MediaSet
+========================
+dmacvicar@suse.de
)
SET( zypp_source_susetags_SRCS
+ source/susetags/SUSETagsDownloader.cc
source/susetags/MediaMetadataParser.cc
source/susetags/MediaPatchesMetadataParser.cc
source/susetags/PackagesLangParser.cc
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
// 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() );
~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);
--- /dev/null
+
+#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
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ 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
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" )
| |
\---------------------------------------------------------------------*/
+#include <iostream>
#include <vector>
+#include <sstream>
+#include <fstream>
#include "zypp/base/Logger.h"
#include "zypp/base/String.h"
{
_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
}
catch(exception &ex)
{
- ERR << "Exception Occured: " << ex.what() << endl;
+ ZYPP_RETHROW(Exception(ex.what()));
+ //ERR << "Exception Occured: " << ex.what() << endl;
}
}
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();
}