From 67e765165a83a528cbbfb42374b4b1a8ad510655 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Fri, 11 Apr 2008 10:04:23 +0000 Subject: [PATCH] switch to new locks api --- zypp.conf | 19 ++++++++++++++++++- zypp/Locks.cc | 43 ------------------------------------------- zypp/Locks.h | 3 --- zypp/ZConfig.cc | 14 +++++++++++++- zypp/ZConfig.h | 8 ++++++++ zypp/zypp_detail/ZYppImpl.cc | 41 ++++++++++++++++++----------------------- 6 files changed, 57 insertions(+), 71 deletions(-) diff --git a/zypp.conf b/zypp.conf index 21fcb9f..945a9e1 100644 --- a/zypp.conf +++ b/zypp.conf @@ -141,4 +141,21 @@ ## Valid values: boolean ## Default value: false ## -# solver.onlyRequires = false \ No newline at end of file +# solver.onlyRequires = false + +## +## Path to locks file. If not exist then is create. +## In this file is saved also UI locks. +## +## valid value: path to file or place where file can be created +## default value: /etc/zypp/locks +## +# locksfile.path = /etc/zypp/locks + +## +## Whetever to apply locks in locks file after zypp start. +## +## Valid values: boolean +## Default value: true +## +# locksfile.apply = true diff --git a/zypp/Locks.cc b/zypp/Locks.cc index 6fc404f..409b12a 100644 --- a/zypp/Locks.cc +++ b/zypp/Locks.cc @@ -34,49 +34,6 @@ namespace zypp { namespace locks { -// -// assign Lock to installed pool item -// - -struct AddLockToPool -{ - AddLockToPool( const ResPool &pool ) - : _pool(pool) - , _count(0) - { - - } - - bool operator()( const std::string & str_r ) - { -#warning MUST FIX LOCK IMPLEMENTATION - // - make Capability's parse 'Name [Op edition]' available so it can be used here - // - provide new, or extend Capability::Matches, functor to allow pattern (glob/rx) matching - return false; - } // end operator()() - - ResPool _pool; - int _count; -}; - -// -// read 'locks' table, evaluate 'glob' column, assign locks to pool -// -int -readLocks(const ResPool & pool, const Pathname &file ) -{ - PathInfo lockrc( file ); - if ( lockrc.isFile() ) - { - MIL << "Reading " << lockrc << endl; - ifstream inp( file.c_str() ); - AddLockToPool addlock(pool); - iostr::forEachLine( inp, addlock); - MIL << addlock._count << " locks." << endl; - return addlock._count; - } - return 0; -} Locks& Locks::instance() { diff --git a/zypp/Locks.h b/zypp/Locks.h index 93375de..d70db91 100644 --- a/zypp/Locks.h +++ b/zypp/Locks.h @@ -11,9 +11,6 @@ namespace zypp { namespace locks { - - int readLocks(const ResPool & pool, const Pathname &file ); - class Locks { public: diff --git a/zypp/ZConfig.cc b/zypp/ZConfig.cc index 33c4da4..6302724 100644 --- a/zypp/ZConfig.cc +++ b/zypp/ZConfig.cc @@ -148,6 +148,7 @@ namespace zypp , repo_refresh_delay ( 10 ) , download_use_patchrpm ( true ) , download_use_deltarpm ( true ) + , apply_locks_file ( true ) , solver_onlyRequires ( false ) { @@ -237,10 +238,14 @@ namespace zypp { solver_onlyRequires = str::strToBool( value, solver_onlyRequires ); } - else if ( entry == "locksfile" ) + else if ( entry == "locksfile.path" ) { locks_file = Pathname(value); } + else if ( entry == "locksfile.apply" ) + { + apply_locks_file = str::strToBool( value, apply_locks_file ); + } } } } @@ -288,6 +293,8 @@ namespace zypp bool solver_onlyRequires; + bool apply_locks_file; + }; /////////////////////////////////////////////////////////////////// @@ -438,6 +445,11 @@ namespace zypp ? Pathname("/etc/zypp/locks") : _pimpl->locks_file ); } + bool ZConfig::apply_locks_file() const + { + return _pimpl->apply_locks_file; + } + ///////////////////////////////////////////////////////////////// } // namespace zypp /////////////////////////////////////////////////////////////////// diff --git a/zypp/ZConfig.h b/zypp/ZConfig.h index 70dba6d..b561576 100644 --- a/zypp/ZConfig.h +++ b/zypp/ZConfig.h @@ -143,8 +143,16 @@ namespace zypp */ bool solver_onlyRequires() const; + /** + * Path where zypp can find or create lock file + */ Pathname locksFile() const; + /** + * Whetever locks file should be readed and applied after start + */ + bool apply_locks_file() const; + public: class Impl; /** Dtor */ diff --git a/zypp/zypp_detail/ZYppImpl.cc b/zypp/zypp_detail/ZYppImpl.cc index f204e17..9e8144b 100644 --- a/zypp/zypp_detail/ZYppImpl.cc +++ b/zypp/zypp_detail/ZYppImpl.cc @@ -23,6 +23,9 @@ #include "zypp/DiskUsageCounter.h" #include "zypp/NameKindProxy.h" #include "zypp/Locks.h" +#include "zypp/ZConfig.h" +#include "zypp/sat/Pool.h" +#include "zypp/PoolItem.h" using std::endl; @@ -176,32 +179,24 @@ namespace zypp int ZYppImpl::applyLocks() { -#warning make the /etc/zypp/locks path an option zconfig. - Pathname locksrcPath( "/etc/zypp/locks" ); - try - { - Target_Ptr trg( target() ); - if ( trg ) - locksrcPath = trg->root() / locksrcPath; - } - catch ( ... ) - { - // noop: Someone decided to let target() throw if the ptr is NULL ;( - } + if (!ZConfig::instance().apply_locks_file()) + return 0; - int num=0; - PathInfo locksrc( locksrcPath ); - if ( locksrc.isFile() ) - { - MIL << "Reading locks from '" << locksrcPath << "'" << endl; - num = zypp::locks::readLocks( pool(), locksrcPath ); - MIL << num << " items locked." << endl; - } - else + //TODO catch posibble exceptions + locks::Locks::instance().loadLocks(); + + //current locks api doesn't support counting lock + //so count it after + int count = 0; + for_(it, sat::Pool::instance().solvablesBegin(), + sat::Pool::instance().solvablesEnd()) { - MIL << "No file '" << locksrcPath << "' to read locks from" << endl; + PoolItem i(*it); + if ( i.status().isLocked() ) + count++; } - return num; + + return count; } /****************************************************************** ** -- 2.7.4