Author: jreidinger
Date: Tue Apr 8 10:48:59 2008
New Revision: 9442
URL: http://svn.opensuse.org/viewcvs/zypp?rev=9442&view=rev
Log:
initial implementation of new locks (FATE #120118 and #120352)
Modified:
trunk/libzypp/zypp/Locks.cc
trunk/libzypp/zypp/Locks.h
trunk/libzypp/zypp/PoolQuery.cc
trunk/libzypp/zypp/ZConfig.cc
trunk/libzypp/zypp/ZConfig.h
trunk/libzypp/zypp/ZYppCallbacks.h
Modified: trunk/libzypp/zypp/Locks.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/Locks.cc?rev=9442&r1=9441&r2=9442&view=diff
==============================================================================
--- trunk/libzypp/zypp/Locks.cc (original)
+++ trunk/libzypp/zypp/Locks.cc Tue Apr 8 10:48:59 2008
@@ -16,6 +16,8 @@
#include "zypp/base/Logger.h"
#include "zypp/base/IOStream.h"
#include "zypp/PoolItem.h"
+#include "zypp/PoolQueryUtil.tcc"
+#include "zypp/ZYppCallbacks.h"
#undef ZYPP_BASE_LOGGER_LOGGROUP
#define ZYPP_BASE_LOGGER_LOGGROUP "locks"
@@ -31,65 +33,6 @@
{
namespace locks
{
-#if 0
-//
-// collect matching names
-//
-// called by regexp matching, see 'Match' below
-//
-
-struct NameMatchCollectorFunc
-{
- set<string> matches;
-
- bool operator()( const PoolItem &item )
- {
- matches.insert( item.resolvable()->name() );
- return true;
- }
-};
-
-
-// taken from zypper
-struct Match
-{
- const regex * _regex;
-
- Match(const regex & regex ) :
- _regex(®ex)
- {}
-
- bool operator()(const zypp::PoolItem & pi) const
- {
- return
- // match resolvable name
- regex_match(pi.resolvable()->name(), *_regex);
- }
-};
-
-
-string
-wildcards2regex(const string & str)
-{
- string regexed;
-
- string all("*"); // regex to search for '*'
- string one("?"); // regex to search for '?'
- string r_all(".*"); // regex equivalent of '*'
- string r_one("."); // regex equivalent of '?'
-
- // replace all "*" in input with ".*"
- regexed = str::gsub( str, all, r_all );
- MIL << "wildcards2regex: " << str << " -> " << regexed;
-
- // replace all "?" in input with "."
- regexed = str::gsub(regexed, one, r_one);
- MIL << " -> " << regexed << endl;
-
- return regexed;
-}
-#endif
-
//
// assign Lock to installed pool item
//
@@ -109,104 +52,6 @@
// - 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;
-#if 0
- CapFactory cap_factory;
-
- std::string line( str::trim( str_r ) );
-
- if ( line.empty() || line[0] == '#')
- return true;
-
- MIL << "Applying locks from pattern '" << str_r << "'" << endl;
-
- // zypp does not provide wildcard or regex support in the Capability matching helpers
- // but it still parses the index if it contains wildcards.
- // so we decompose the capability, and keep the op and edition, while, the name
- // is converted to a regexp and matched against all possible names in the _pool
- // Then these names are combined with the original edition and relation and we
- // got a new capability for matching wildcard to use with the capability match
- // helpers
-
- Rel rel;
- Edition edition;
- string name;
-
- try
- {
- Capability capability = cap_factory.parse( ResTraitszypp::Package::kind, line );
-
- capability::NamedCap::constPtr named = capability::asKindcapability::NamedCap(capability);
- if ( named )
- {
- rel = named->op();
- edition = named->edition();
- name = named->index();
- }
- else
- {
- ERR << "Not a named capability in: '" << line << "' skipping" << std::endl;
- return true;
- }
- }
- catch ( const Exception &e )
- {
- ERR << "Can't parse capability in: '" << line << "' (" << e.msg() << ") skipping" << std::endl;
- return true;
- }
-
- // Operator NONE is not allowed in Capability
- if (rel == Rel::NONE) rel = Rel::ANY;
-
- NameMatchCollectorFunc nameMatchFunc;
-
- // regex flags
- unsigned int flags = regex::normal;
- flags |= regex::icase;
- regex reg;
-
- // create regex object
- string regstr( wildcards2regex( name ) );
- MIL << "regstr '" << regstr << "'" << endl;
- try
- {
- reg.assign( regstr, flags );
- }
- catch (regex_error & e)
- {
- ERR << "locks: " << regstr << " is not a valid regular expression: \"" << e.msg() << "\"" << endl;
- ERR << "This is a bug, please file a bug report against libzypp" << endl;
- // ignore this lock and continue
- return true;;
- }
-
- invokeOnEach( _pool.begin(), _pool.end(), Match(reg), functor::functorRef(nameMatchFunc) );
-
- MIL << "Found " << nameMatchFunc.matches.size() << " matches." << endl;
-
- // now we have all the names matching
-
- // for each name matching try to match a capability
-
- ItemLockerFunc lockItemFunc( line );
-
- for ( set<string>::const_iterator it = nameMatchFunc.matches.begin(); it != nameMatchFunc.matches.end(); ++it )
- {
- string matched_name = *it;
-
- try
- {
- Capability capability = cap_factory.parse( ResTraitszypp::Package::kind, matched_name, rel, edition );
- MIL << "Locking capability " << capability << endl;
- forEachMatchIn( _pool, Dep::PROVIDES, capability, functor::functorRef(lockItemFunc) );
- }
- catch ( const Exception &e )
- {
- ERR << "Invalid lock: " << e.msg() << std::endl;
- }
- ++_count;
- }
- return true;
-#endif
} // end operator()()
ResPool _pool;
@@ -232,5 +77,111 @@
return 0;
}
+class Locks::Impl
+{
+public:
+ std::list<PoolQuery> locks;
+};
+
+void Locks::saveLocks( const Pathname& file )
+{
+ writePoolQueriesToFile( file, _pimpl->locks.begin(), _pimpl->locks.end() );
+}
+
+void Locks::loadLocks( const Pathname& file )
+{
+ _pimpl->locks.clear();
+ insert_iterator ii( _pimpl->locks,
+ _pimpl->locks.end() );
+ readPoolQueriesFromFile( file, ii );
+}
+
+void Locks::addLock( const PoolQuery& query )
+{
+ //XXX real lock it!
+ _pimpl->locks.push_back( query );
+}
+
+bool Locks::existEmptyLocks()
+{
+ for_( it, _pimpl->locks.begin(), _pimpl->locks.end() )
+ {
+ if( it->empty() )
+ return true;
+ }
+
+ return false;
+}
+
+//handle locks during removing
+class LocksRemovePredicate{
+private:
+ bool skip_rest;
+ size_t searched;
+ size_t all;
+ callback::SendReport<CleanEmptyLocksReport> &report;
+
+public:
+ LocksRemovePredicate(size_t count, callback::SendReport<CleanEmptyLocksReport> &_report): skip_rest(false),searched(0),all(count), report(_report){}
+
+ bool aborted(){ return skip_rest; }
+
+ bool operator()(PoolQuery& q)
+ {
+ if( skip_rest )
+ return false;
+ searched++;
+ if( !q.empty() )
+ return false;
+
+ if (!report->progress((100*searched)/all))
+ {
+ skip_rest = true;
+ return false;
+ }
+
+ switch (report->execute(q))
+ {
+ case CleanEmptyLocksReport::ABORT:
+ report->finish(CleanEmptyLocksReport::ABORTED);
+ skip_rest = true;
+ return false;
+ case CleanEmptyLocksReport::DELETE:
+ return true;
+ case CleanEmptyLocksReport::IGNORE:
+ return false;
+ default:
+ WAR << "Unknown returned value. Callback have more value then"
+ << " this switch. Need correct handle all enum values." << std::endl;
+ }
+
+ return false;
+ }
+
+};
+
+void Locks::removeEmptyLocks()
+{
+ callback::SendReport<CleanEmptyLocksReport> report;
+ report->start();
+ size_t sum = _pimpl->locks.size();
+ LocksRemovePredicate p(sum, report);
+
+ _pimpl->locks.remove_if(p);
+
+ if( p.aborted() )
+ {
+ report->finish(CleanEmptyLocksReport::ABORTED);
+ }
+ else
+ {
+ report->finish(CleanEmptyLocksReport::NO_ERROR);
+
+ }
+}
+
+Locks::Locks(){}
+
+
} // ns locks
} // ns zypp
Modified: trunk/libzypp/zypp/Locks.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/Locks.h?rev=9442&r1=9441&r2=9442&view=diff
==============================================================================
--- trunk/libzypp/zypp/Locks.h (original)
+++ trunk/libzypp/zypp/Locks.h Tue Apr 8 10:48:59 2008
@@ -4,6 +4,8 @@
#include "zypp/ResPool.h"
#include "zypp/Pathname.h"
+#include "zypp/PoolQuery.h"
+#include "zypp/ZConfig.h"
namespace zypp
{
@@ -11,6 +13,39 @@
{
int readLocks(const ResPool & pool, const Pathname &file );
+
+ class Locks
+ {
+ public:
+ class Impl;
+
+ static Locks instance;
+
+ /**
+ * locks all solvables which is result of query
+ */
+ void addLock( const PoolQuery& query );
+
+ /**
+ * unlocks all solvables which is result of query.
+ * Can call callback
+ */
+ void unlock( const PoolQuery& query );
+
+ void loadLocks( const Pathname& file = ZConfig::instance().locksFile() );
+
+ void saveLocks( const Pathname& file = ZConfig::instance().locksFile() );
+
+ bool existEmptyLocks();
+
+ void removeEmptyLocks();
+
+ private:
+ Locks();
+
+ RW_pointer _pimpl;
+
+ };
}
}
Modified: trunk/libzypp/zypp/PoolQuery.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/PoolQuery.cc?rev=9442&r1=9441&r2=9442&view=diff
==============================================================================
--- trunk/libzypp/zypp/PoolQuery.cc (original)
+++ trunk/libzypp/zypp/PoolQuery.cc Tue Apr 8 10:48:59 2008
@@ -877,7 +877,6 @@
return finded_something;
}
-
void PoolQuery::serialize( ostream &str, char delim ) const
{
//separating delim
Modified: trunk/libzypp/zypp/ZConfig.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/ZConfig.cc?rev=9442&r1=9441&r2=9442&view=diff
==============================================================================
--- trunk/libzypp/zypp/ZConfig.cc (original)
+++ trunk/libzypp/zypp/ZConfig.cc Tue Apr 8 10:48:59 2008
@@ -237,6 +237,10 @@
{
solver_onlyRequires = str::strToBool( value, solver_onlyRequires );
}
+ else if ( entry == "locksfile" )
+ {
+ locks_file = Pathname(value);
+ }
}
}
}
@@ -274,6 +278,7 @@
Pathname cfg_cache_path;
Pathname cfg_known_repos_path;
Pathname cfg_vendor_path;
+ Pathname locks_file;
bool repo_add_probe;
unsigned repo_refresh_delay;
@@ -427,6 +432,12 @@
bool ZConfig::solver_onlyRequires() const
{ return _pimpl->solver_onlyRequires; }
+ Pathname ZConfig::locksFile() const
+ {
+ return ( _pimpl->locks_file.empty()
+ ? Pathname("/etc/zypp/locks") : _pimpl->locks_file );
+ }
+
/////////////////////////////////////////////////////////////////
} // namespace zypp
///////////////////////////////////////////////////////////////////
Modified: trunk/libzypp/zypp/ZConfig.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/ZConfig.h?rev=9442&r1=9441&r2=9442&view=diff
==============================================================================
--- trunk/libzypp/zypp/ZConfig.h (original)
+++ trunk/libzypp/zypp/ZConfig.h Tue Apr 8 10:48:59 2008
@@ -143,6 +143,8 @@
*/
bool solver_onlyRequires() const;
+ Pathname locksFile() const;
+
public:
class Impl;
/** Dtor */
Modified: trunk/libzypp/zypp/ZYppCallbacks.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/ZYppCallbacks.h?rev=9442&r1=9441&r2=9442&view=diff
==============================================================================
--- trunk/libzypp/zypp/ZYppCallbacks.h (original)
+++ trunk/libzypp/zypp/ZYppCallbacks.h Tue Apr 8 10:48:59 2008
@@ -16,6 +16,7 @@
#include "zypp/Resolvable.h"
#include "zypp/RepoInfo.h"
#include "zypp/Pathname.h"
+#include "zypp/PoolQuery.h"
#include "zypp/Message.h"
#include "zypp/Url.h"
#include "zypp/ProgressData.h"
@@ -622,6 +623,46 @@
} // namespace target
///////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace locks
+ {
+ struct CleanEmptyLocksReport : public callback::ReportBase
+ {
+ enum Action {
+ ABORT, // abort and return error
+ DELETE, // delete empty lock
+ IGNORE // skip empty lock
+ };
+
+ enum Error {
+ NO_ERROR,
+ ABORTED // cleaning aborted
+ };
+
+ virtual void start(
+ ) {}
+
+ virtual bool progress(int /*value*/)
+ { return true; }
+
+ /**
+ * When find empty lock ask what to do with it
+ */
+ virtual Action execute(
+ const PoolQuery& /*error*/
+ ) { return DELETE; }
+
+ virtual void finish(
+ Error /*error*/
+ ) {}
+
+ };
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace locks
+ ///////////////////////////////////////////////////////////////////
+
+
/////////////////////////////////////////////////////////////////
} // namespace zypp
///////////////////////////////////////////////////////////////////
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org