![](https://seccdn.libravatar.org/avatar/d5900b51dba6d927d3feaf3b73360d4f.jpg?s=120&d=mm&r=g)
Author: dmacvicar Date: Tue Sep 11 16:13:31 2007 New Revision: 7187 URL: http://svn.opensuse.org/viewcvs/zypp?rev=7187&view=rev Log: - restore deltas and patches from the cache (#309124) Modified: trunk/libzypp/tests/cache/CacheStore_test.cc trunk/libzypp/zypp/cache/CacheInitializer.h trunk/libzypp/zypp/cache/CacheStore.cc trunk/libzypp/zypp/cache/schema/schema.sql trunk/libzypp/zypp/repo/RepositoryImpl.cc trunk/libzypp/zypp/repo/RepositoryImpl.h trunk/libzypp/zypp/repo/cached/RepoImpl.cc Modified: trunk/libzypp/tests/cache/CacheStore_test.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/tests/cache/CacheStore_test.cc?rev=7187&r1=7186&r2=7187&view=diff ============================================================================== --- trunk/libzypp/tests/cache/CacheStore_test.cc (original) +++ trunk/libzypp/tests/cache/CacheStore_test.cc Tue Sep 11 16:13:31 2007 @@ -444,6 +444,32 @@ cache_write_shared_attributes(repodir); } +/** + * \short Test that a yum repo wrtes and reads back patch and delta rpm information + */ +void cache_delta_rpm_test(const string &dir) +{ + Pathname repodir = Pathname(dir) + "/repo/yum/data/10.2-updates-subset"; + filesystem::TmpDir tmpdir; + string alias = "novell.com"; + write_yum_repo( alias, repodir, tmpdir ); + + data::RecordId repository_id; + { + cache::CacheStore store(tmpdir.path()); + repository_id = store.lookupOrAppendRepository(alias); + } + + cached::RepoImpl *repositoryImpl = new cached::RepoImpl( cached::RepoOptions( RepoInfo(), + tmpdir.path(), + repository_id )); + // 22 packages and 6 patches + BOOST_CHECK_EQUAL( repositoryImpl->resolvables().size(), 42 ); + // 19 patch rpms + BOOST_CHECK_EQUAL( repositoryImpl->patchRpms().size(), 19 ); + //check_tables_clean(tmpdir); +} + test_suite* init_unit_test_suite( int argc, char *argv[] ) { @@ -484,6 +510,10 @@ (std::string const*)params, params+1)); test->add(BOOST_PARAM_TEST_CASE(&cache_write_shared_attributes_test, (std::string const*)params, params+1)); + + // test for delta and patch rpms + test->add(BOOST_PARAM_TEST_CASE(&cache_delta_rpm_test, + (std::string const*)params, params+1)); return test; } Modified: trunk/libzypp/zypp/cache/CacheInitializer.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/cache/CacheInitializer.h?rev=7187&r1=7186&r2=7187&view=diff ============================================================================== --- trunk/libzypp/zypp/cache/CacheInitializer.h (original) +++ trunk/libzypp/zypp/cache/CacheInitializer.h Tue Sep 11 16:13:31 2007 @@ -19,7 +19,7 @@ #include "zypp/Pathname.h" #include "zypp/cache/sqlite3x/sqlite3x.hpp" -#define ZYPP_CACHE_SCHEMA_VERSION 1004 +#define ZYPP_CACHE_SCHEMA_VERSION 1005 /////////////////////////////////////////////////////////////////// namespace zypp Modified: trunk/libzypp/zypp/cache/CacheStore.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/cache/CacheStore.cc?rev=7187&r1=7186&r2=7187&view=diff ============================================================================== --- trunk/libzypp/zypp/cache/CacheStore.cc (original) +++ trunk/libzypp/zypp/cache/CacheStore.cc Tue Sep 11 16:13:31 2007 @@ -122,13 +122,13 @@ count_shared_cmd.reset( new sqlite3_command( con, "select count(id) from resolvables where shared_id=:rid;" )); insert_patchrpm_cmd.reset( new sqlite3_command (con, - "insert into patch_packages (repository_id, media_nr, location, checksum, download_size, build_time) " - "values (:repository_id, :media_nr, :location, :checksum, :download_size, :build_time);" )); + "insert into patch_packages (repository_id, media_nr, location, checksum, checksum_type, download_size, build_time) " + "values (:repository_id, :media_nr, :location, :checksum, :checksum_type, :download_size, :build_time);" )); insert_deltarpm_cmd.reset( new sqlite3_command (con, - "insert into delta_packages (repository_id, media_nr, location, checksum, download_size, build_time, " + "insert into delta_packages (repository_id, media_nr, location, checksum, checksum_type, download_size, build_time, " "baseversion_version, baseversion_release, baseversion_epoch, baseversion_checksum, " "baseversion_build_time, baseversion_sequence_info) " - "values (:repository_id, :media_nr, :location, :checksum, :download_size, :build_time, " + "values (:repository_id, :media_nr, :location, :checksum, :checksum_type, :download_size, :build_time, " ":baseversion_version, :baseversion_release, :baseversion_epoch, :baseversion_checksum, " ":baseversion_build_time, :baseversion_sequence_info);" )); append_patch_baseversion_cmd.reset( new sqlite3_command (con, @@ -747,6 +747,7 @@ _pimpl->insert_patchrpm_cmd->bind(":repository_id", repository_id); _pimpl->insert_patchrpm_cmd->bind(":location", prpm->location.filename().asString()); _pimpl->insert_patchrpm_cmd->bind(":checksum", prpm->location.checksum().checksum()); + _pimpl->insert_patchrpm_cmd->bind(":checksum_type", prpm->location.checksum().type()); //! \todo checksum type _pimpl->insert_patchrpm_cmd->bind(":download_size", static_cast<ByteCount::SizeType>(prpm->location.downloadSize())); _pimpl->insert_patchrpm_cmd->bind(":build_time", prpm->buildTime.asSeconds()); @@ -777,6 +778,8 @@ _pimpl->insert_deltarpm_cmd->bind(":repository_id", repository_id); _pimpl->insert_deltarpm_cmd->bind(":location", drpm->location.filename().asString()); _pimpl->insert_deltarpm_cmd->bind(":checksum", drpm->location.checksum().checksum()); + _pimpl->insert_deltarpm_cmd->bind(":checksum", drpm->location.checksum().checksum()); + _pimpl->insert_deltarpm_cmd->bind(":checksum_type", drpm->location.checksum().type()); //! \todo checksum type _pimpl->insert_deltarpm_cmd->bind(":download_size", static_cast<ByteCount::SizeType>(drpm->location.downloadSize())); _pimpl->insert_deltarpm_cmd->bind(":build_time", drpm->buildTime.asSeconds()); Modified: trunk/libzypp/zypp/cache/schema/schema.sql URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/cache/schema/schema.sql?rev=7187&r1=7186&r2=7187&view=diff ============================================================================== --- trunk/libzypp/zypp/cache/schema/schema.sql (original) +++ trunk/libzypp/zypp/cache/schema/schema.sql Tue Sep 11 16:13:31 2007 @@ -169,12 +169,14 @@ , media_nr INTEGER , location TEXT , checksum TEXT + , checksum_type TEXT , download_size INTEGER , build_time INTEGER , baseversion_version TEXT , baseversion_release TEXT , baseversion_epoch INTEGER , baseversion_checksum TEXT + , baseversion_checksum_type TEXT , baseversion_build_time INTEGER , baseversion_sequence_info TEXT , repository_id INTEGER REFERENCES repositories(id) @@ -186,6 +188,7 @@ , media_nr INTEGER , location TEXT , checksum TEXT + , checksum_type TEXT , download_size INTEGER , build_time INTEGER , repository_id INTEGER REFERENCES repositories(id) Modified: trunk/libzypp/zypp/repo/RepositoryImpl.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/repo/RepositoryImpl.cc?rev=7187&r1=7186&r2=7187&view=diff ============================================================================== --- trunk/libzypp/zypp/repo/RepositoryImpl.cc (original) +++ trunk/libzypp/zypp/repo/RepositoryImpl.cc Tue Sep 11 16:13:31 2007 @@ -11,6 +11,7 @@ RepositoryImpl::RepositoryImpl( const RepoInfo &info ) : _restore_lazy_initialized(false), + _deltas_lazy_initialized(false), _info(info) { @@ -54,13 +55,23 @@ const std::list<packagedelta::PatchRpm> & RepositoryImpl::patchRpms() const { + if ( ! _deltas_lazy_initialized ) + { + const_cast<RepositoryImpl*>(this)->createPatchAndDeltas(); + const_cast<RepositoryImpl*>(this)->_deltas_lazy_initialized = true; + } return _patchRpms; } const std::list<packagedelta::DeltaRpm> & RepositoryImpl::deltaRpms() const { - return _deltaRpms; + if ( ! _deltas_lazy_initialized ) + { + const_cast<RepositoryImpl*>(this)->createPatchAndDeltas(); + const_cast<RepositoryImpl*>(this)->_deltas_lazy_initialized = true; + } + return _deltaRpms; } } } // ns Modified: trunk/libzypp/zypp/repo/RepositoryImpl.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/repo/RepositoryImpl.h?rev=7187&r1=7186&r2=7187&view=diff ============================================================================== --- trunk/libzypp/zypp/repo/RepositoryImpl.h (original) +++ trunk/libzypp/zypp/repo/RepositoryImpl.h Tue Sep 11 16:13:31 2007 @@ -77,6 +77,8 @@ std::list<packagedelta::DeltaRpm> _deltaRpms; private: bool _restore_lazy_initialized; + bool _deltas_lazy_initialized; + RepoInfo _info; }; } Modified: trunk/libzypp/zypp/repo/cached/RepoImpl.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/repo/cached/RepoImpl.cc?rev=7187&r1=7186&r2=7187&view=diff ============================================================================== --- trunk/libzypp/zypp/repo/cached/RepoImpl.cc (original) +++ trunk/libzypp/zypp/repo/cached/RepoImpl.cc Tue Sep 11 16:13:31 2007 @@ -174,19 +174,6 @@ //extract_packages_from_directory( _store, thePath, selfRepositoryRef(), true ); } -static CheckSum encoded_string_to_checksum( const std::string &encoded ) -{ - vector<string> words; - if ( str::split( encoded, std::back_inserter(words), ":" ) != 2 ) - { - return CheckSum(); - } - else - { - return CheckSum( words[0], words[1] ); - } -} - void RepoImpl::createPatchAndDeltas() { ProgressData ticks; @@ -201,8 +188,8 @@ con.executenonquery("BEGIN;"); string pp_query = - // 0 1 2 3 4 5 - "SELECT id, media_nr, location, checksum, download_size, build_time " + // 0 1 2 3 4 5 + "SELECT id, media_nr, location, checksum, checksum_type, download_size, build_time " "FROM patch_packages WHERE repository_id=:repository_id;"; string pp_bv_query = @@ -210,92 +197,101 @@ "FROM patch_packages_baseversions WHERE patch_package_id = :patch_package_id"; string delta_query = - // 0 1 2 3 4 5 6 7 8 9 10 - "SELECT id, media_nr, location, checksum, download_size, build_time, baseversion_version, baseversion_release, baseversion_epoch, baseversion_checksum, baseversion_build_time " + // 0 1 2 3 4 5 6 7 8 9 10 11 + "SELECT id, media_nr, location, checksum, checksum_type, download_size, build_time, baseversion_version, baseversion_release, baseversion_epoch, baseversion_checksum, baseversion_checksum_type, baseversion_build_time " // 11 ", baseversion_sequence_info " "FROM delta_packages WHERE repository_id=:repository_id;"; - - // bind the master repo id to the query - sqlite3_command deltas_cmd( con, delta_query); - deltas_cmd.bind(":repository_id", _options.repository_id); - sqlite3_reader reader = deltas_cmd.executereader(); - while ( reader.read() ) + { - zypp::OnMediaLocation on_media( reader.getstring(2), reader.getint(1) ); - - string checksum_string(reader.getstring(3)); - CheckSum checksum = encoded_string_to_checksum(checksum_string); - if ( checksum.empty() ) - { - ERR << "Wrong checksum for delta, skipping..." << endl; - continue; - } - on_media.setChecksum(checksum); - on_media.setDownloadSize(reader.getint(4)); - - packagedelta::DeltaRpm::BaseVersion baseversion; - baseversion.setEdition( Edition(reader.getstring(6), reader.getstring(7), reader.getstring(8) ) ); - - checksum_string = reader.getstring(9); - checksum = encoded_string_to_checksum(checksum_string); - if ( checksum.empty() ) + // bind the master repo id to the query + sqlite3_command deltas_cmd( con, delta_query); + deltas_cmd.bind(":repository_id", _options.repository_id); + sqlite3_reader reader = deltas_cmd.executereader(); + while ( reader.read() ) { - ERR << "Wrong checksum for delta, skipping..." << endl; - continue; + zypp::OnMediaLocation on_media( reader.getstring(2), reader.getint(1) ); + + string checksum_string(reader.getstring(3)); + CheckSum checksum(reader.getstring(4), reader.getstring(3)); + if ( checksum.empty() ) + { + ERR << "Wrong checksum for delta, skipping..." << endl; + continue; + } + on_media.setChecksum(checksum); + on_media.setDownloadSize(reader.getint(5)); + + packagedelta::DeltaRpm::BaseVersion baseversion; + baseversion.setEdition( Edition(reader.getstring(7), reader.getstring(8), reader.getstring(9) ) ); + + checksum = CheckSum(reader.getstring(11), reader.getstring(10)); + if ( checksum.empty() ) + { + ERR << "Wrong checksum for delta, skipping..." << endl; + continue; + } + baseversion.setChecksum(checksum); + baseversion.setBuildtime(reader.getint(12)); + baseversion.setSequenceinfo(reader.getstring(13)); + + zypp::packagedelta::DeltaRpm delta; + delta.setLocation( on_media ); + delta.setBaseversion( baseversion ); + delta.setBuildtime(reader.getint(6)); + + _deltaRpms.push_back(delta); } - baseversion.setChecksum(checksum); - baseversion.setBuildtime(reader.getint(10)); - baseversion.setSequenceinfo(reader.getstring(11)); - - zypp::packagedelta::DeltaRpm delta; - delta.setLocation( on_media ); - delta.setBaseversion( baseversion ); - delta.setBuildtime(reader.getint(5)); - - _deltaRpms.push_back(delta); + reader.close(); } - - // patch rpms - // bind the master package id to the query - // bind the master repo id to the query - sqlite3_command pp_cmd( con, pp_query); - sqlite3_command pp_bv_cmd( con, pp_bv_query); - pp_cmd.bind(":repository_id", _options.repository_id); - reader = pp_cmd.executereader(); - - while ( reader.read() ) { - long long patch_package_id = reader.getint64(0); - - zypp::OnMediaLocation on_media( reader.getstring(2), reader.getint(1) ); - - string checksum_string(reader.getstring(3)); - CheckSum checksum = encoded_string_to_checksum(checksum_string); - if ( checksum.empty() ) + // patch rpms + // bind the master package id to the query + // bind the master repo id to the query + sqlite3_command pp_cmd( con, pp_query); + sqlite3_command pp_bv_cmd( con, pp_bv_query); + pp_cmd.bind(":repository_id", _options.repository_id); + sqlite3_reader reader = pp_cmd.executereader(); + + while ( reader.read() ) { - ERR << "Wrong checksum for delta, skipping..." << endl; - continue; + //MIL << "Addining patch rpm " << endl; + long long patch_package_id = reader.getint64(0); + + zypp::OnMediaLocation on_media( reader.getstring(2), reader.getint(1) ); + + CheckSum checksum(reader.getstring(4), reader.getstring(3)); + if ( checksum.empty() ) + { + ERR << "Wrong checksum for delta, skipping..." << endl; + continue; + } + on_media.setChecksum(checksum); + on_media.setDownloadSize(reader.getint(5)); + + zypp::packagedelta::PatchRpm patch; + patch.setLocation( on_media ); + patch.setBuildtime(reader.getint(6)); + + pp_bv_cmd.bind( ":patch_package_id", patch_package_id ); + + sqlite3_reader bv_reader = pp_bv_cmd.executereader(); + while (bv_reader.read()) + { + //MIL << " * Adding baseversion " << endl; + packagedelta::PatchRpm::BaseVersion baseversion = packagedelta::PatchRpm::BaseVersion( bv_reader.getstring(0) , bv_reader.getstring(1), bv_reader.getint(2) ); + patch.addBaseversion(baseversion); + } + + bv_reader.close(); + + _patchRpms.push_back(patch); } - on_media.setChecksum(checksum); - on_media.setDownloadSize(reader.getint(4)); - - zypp::packagedelta::PatchRpm patch; - patch.setLocation( on_media ); - patch.setBuildtime(reader.getint(5)); - - pp_bv_cmd.bind( ":patch_package_id", patch_package_id ); - - sqlite3_reader bv_reader = pp_bv_cmd.executereader(); - while (bv_reader.read()) - { - packagedelta::PatchRpm::BaseVersion baseversion = packagedelta::PatchRpm::BaseVersion( bv_reader.getstring(0) , bv_reader.getstring(1), bv_reader.getint(2) ); - patch.addBaseversion(baseversion); - } - - _patchRpms.push_back(patch); + reader.close(); + MIL << _patchRpms.size() << " patch rpms read." << endl; } - con.resetprogresshandler(); + //con.resetprogresshandler(); + con.close(); } catch(exception &ex) { cerr << "Exception Occured: " << ex.what() << endl; -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org