From fad7010cd4b30ec9493acf6584cda1632fe544e3 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Fri, 11 Apr 2008 15:16:01 +0000 Subject: [PATCH] test for save/restoring locks and also unlocking --- tests/zypp/Locks_test.cc | 40 ++++++++++++++++++++++++++++++++++++++++ tests/zypp/data/Locks/locks | 6 +----- zypp/Locks.cc | 15 +++++++++++++-- 3 files changed, 54 insertions(+), 7 deletions(-) diff --git a/tests/zypp/Locks_test.cc b/tests/zypp/Locks_test.cc index b27a443..6f10a51 100644 --- a/tests/zypp/Locks_test.cc +++ b/tests/zypp/Locks_test.cc @@ -79,3 +79,43 @@ BOOST_AUTO_TEST_CASE(locks_2) BOOST_CHECK(isLocked(*it)); } } + +BOOST_AUTO_TEST_CASE(locks_save_load) +{ + cout << "****save/load****" << endl; + Pathname src(TESTS_SRC_DIR); + src += "zypp/data/Locks/locks"; + Locks::instance().loadLocks(src); + PoolQuery q; + q.addString("zypper"); + for_(it,q.begin(),q.end()) + { + BOOST_CHECK(isLocked(*it)); + } + Locks::instance().unlock(q); + for_(it,q.begin(),q.end()) + { + BOOST_CHECK(!isLocked(*it)); + } +#if 1 + filesystem::TmpFile testfile; + //Pathname testfile(TESTS_SRC_DIR); + // testfile += "/zypp/data/Locks/testlocks"; + Locks::instance().saveLocks(testfile); + Locks::instance().loadLocks(testfile); + //still locked + for_(it,q.begin(),q.end()) + { + BOOST_CHECK(isLocked(*it)); + } + Locks::instance().unlock(q); //need twice because finded from previous test + Locks::instance().saveLocks(testfile); + Locks::instance().loadLocks(testfile); + //now unlocked - first unlock remove indetical lock from previous test + //and next unlock remove lock from lockfile + for_(it,q.begin(),q.end()) + { + BOOST_CHECK(!isLocked(*it)); + } +#endif +} diff --git a/tests/zypp/data/Locks/locks b/tests/zypp/data/Locks/locks index 9e3fcf2..873fa82 100644 --- a/tests/zypp/data/Locks/locks +++ b/tests/zypp/data/Locks/locks @@ -1,5 +1 @@ -#repo cannot be tested due to possibly missing allias -kind: patch - -string: kde -attribute: pattern +global_string: zypper diff --git a/zypp/Locks.cc b/zypp/Locks.cc index ecc3e77..b734851 100644 --- a/zypp/Locks.cc +++ b/zypp/Locks.cc @@ -20,12 +20,12 @@ #include "zypp/PoolQueryUtil.tcc" #include "zypp/ZYppCallbacks.h" #include "zypp/sat/SolvAttr.h" +#include "zypp/PathInfo.h" #undef ZYPP_BASE_LOGGER_LOGGROUP #define ZYPP_BASE_LOGGER_LOGGROUP "locks" #include "zypp/Locks.h" -#include "zypp/PathInfo.h" using namespace std; using namespace zypp; @@ -100,10 +100,12 @@ void Locks::addLock( const PoolQuery& query ) _pimpl->toRemove.end(), query); if ( i != _pimpl->toRemove.end() ) { + DBG << "query removed from toRemove" << endl; _pimpl->toRemove.erase(i); } else { + DBG << "query added as new" << endl; _pimpl->toAdd.push_back( query ); } } @@ -131,10 +133,12 @@ void Locks::unlock( const PoolQuery& query ) _pimpl->toAdd.end(), query); if ( i != _pimpl->toAdd.end() ) { + DBG << "query removed from added" << endl; _pimpl->toAdd.erase(i); } else { + DBG << "needed remove some old lock" << endl; _pimpl->toRemove.push_back( query ); } } @@ -264,8 +268,11 @@ public: { if (aborted()) return false; - if( q==query ) //identical + if( q==query ) + {//identical + DBG << "identical queries" << endl; return true; + } SavingLocksReport::ConflictState cs; switch( contains(q,solvs) ) @@ -284,10 +291,13 @@ public: { case SavingLocksReport::ABORT: aborted_ = true; + DBG << "abort merging" << endl; return false; case SavingLocksReport::DELETE: + DBG << "force delete" << endl; return true; case SavingLocksReport::IGNORE: + DBG << "skip lock" << endl; return false; } WAR << "should not reached, some state is missing" << endl; @@ -322,6 +332,7 @@ void Locks::saveLocks( const Pathname& file ) report->finish(SavingLocksReport::ABORTED); return; } + DBG << "writed "<< _pimpl->locks.size() << "locks" << endl; writePoolQueriesToFile( file, _pimpl->locks.begin(), _pimpl->locks.end() ); report->finish(SavingLocksReport::NO_ERROR); } -- 2.7.4