12 #include <boost/function.hpp>
13 #include <boost/function_output_iterator.hpp>
27 #undef ZYPP_BASE_LOGGER_LOGGROUP
28 #define ZYPP_BASE_LOGGER_LOGGROUP "locks"
39 static Locks _instance;
45 template <
typename TPredicate>
48 LockSet::iterator first = lockset_r.begin();
49 LockSet::iterator last = lockset_r.end();
50 while ( first != last )
52 LockSet::iterator next = first;
54 if ( pred_r( *first ) )
55 lockset_r.erase( first );
104 {
return _pimpl->APIlocks().begin(); }
107 {
return _pimpl->APIlocks().end(); }
110 {
return _pimpl->locks().size(); }
113 {
return _pimpl->locks().empty(); }
132 template <
class OutputIterator>
151 MIL <<
"read and apply locks from "<<file << endl;
152 PathInfo pinfo(file);
153 if ( pinfo.isExist() )
155 std::insert_iterator<LockSet> ii(
_pimpl->MANIPlocks(),
_pimpl->MANIPlocks().end() );
160 MIL <<
"file does not exist(or cannot be stat), no lock added." << endl;
166 MIL <<
"read locks from "<<file << endl;
167 PathInfo pinfo(file);
168 if ( pinfo.isExist() )
171 MIL <<
"file does not exist(or cannot be stat), no lock added." << endl;
177 DBG <<
"apply locks" << endl;
184 MIL <<
"add new lock" << endl;
190 if (
_pimpl->toRemove.erase( query ) )
192 DBG <<
"query removed from toRemove" << endl;
196 DBG <<
"query added as new" << endl;
197 _pimpl->toAdd.insert( query );
219 DBG <<
"add lock by identifier" << endl;
225 MIL <<
"remove lock" << endl;
232 if (
_pimpl->toAdd.erase( query ) )
234 DBG <<
"query removed from added" << endl;
238 DBG <<
"need to remove some old lock" << endl;
239 _pimpl->toRemove.insert( query );
261 DBG <<
"remove lock by Selectable" << endl;
303 switch (
report->execute(q))
314 INT <<
"Unexpected return value from callback. Need to adapt switch statement." << std::endl;
324 MIL <<
"clean of locks" << endl;
327 size_t sum =
_pimpl->locks().size();
334 MIL <<
"cleaning aborted" << endl;
343 if ( sum !=
_pimpl->locks().size() )
344 _pimpl->locksDirty =
true;
358 bool intersect =
false;
361 if ( s.find(*it)!=s.end() )
371 return intersect ? 1 : 0;
385 DBG <<
"identical queries" << endl;
403 MIL <<
"find conflict: " << cs << endl;
404 switch (
report->conflict(q,cs))
408 DBG <<
"abort merging" << endl;
411 DBG <<
"force delete" << endl;
414 DBG <<
"skip lock" << endl;
417 INT <<
"Unexpected return value from callback. Need to adapt switch statement." << std::endl;
426 MIL <<
"merge list old: " <<
locks().size()
427 <<
" to add: " <<
toAdd.size() <<
"to remove: " <<
toRemove.size() << endl;
430 std::set<sat::Solvable> s(it->begin(),it->end());
434 if (!report->progress())
447 if( (
_pimpl->toAdd.size() |
_pimpl->toRemove.size())==0)
454 if (!
_pimpl->mergeList(report))
459 DBG <<
"locks merged" << endl;
461 _pimpl->locksDirty =
true;
466 if( ((
_pimpl->toAdd.size() |
_pimpl->toRemove.size())==0)
469 DBG <<
"nothing changed in locks - no write to file" << endl;
476 if ((
_pimpl->toAdd.size() |
_pimpl->toRemove.size())!=0)
478 if (!
_pimpl->mergeList(report))
485 DBG <<
"wrote "<<
_pimpl->locks().size() <<
"locks" << endl;
LocksRemovePredicate(std::set< sat::Solvable > &s, const PoolQuery &q, callback::SendReport< SavingLocksReport > &r)
void operator()(const PoolQuery &query) const
void addAttribute(const sat::SolvAttr &attr, const std::string &value="")
Filter by the value of the specified attr attribute.
void operator()(const PoolQuery &query) const
void removeEmpty()
Call callback for each empty lock.
void readPoolQueriesFromFile(const zypp::filesystem::Pathname &file, OutputIterator out)
sends to output iterator all queries readed from file.
LockingOutputIterator(OutputIterator &out_)
const_iterator begin() const
const LockSet & locks() const
void setCaseSensitive(bool value=true)
Turn case sentitivity on or off (unsets or sets SEARCH_NOCASE flag).
Access to the sat-pools string space.
void addKind(const ResKind &kind)
Filter by selectable kind.
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
LockList::size_type size() const
RW_pointer< Impl, rw_pointer::Scoped< Impl > > _pimpl
void addLock(const PoolQuery &query)
TODO add: toBeAdded{Begin,End,Size,Empty} toBeRemoved{Begin,End,Size,Empty}.
std::string asString() const
Conversion to std::string
bool operator()(const PoolQuery &q)
Singleton class which manipulate with locks file and apply locks on pool.
locks lock some file and unlocking lock unlock only part of iti, so removing old lock can unlock more...
void apply() const
Applies locks in stable list (locks which is not changed during session).
std::list< PoolQuery > LockList
ResObject::constPtr resolvable() const
Returns the ResObject::constPtr.
void removeDuplicates()
Delete all query duplicate in loaded locks.
static Locks & instance()
Gets instance of this class.
Convenience char* constructible from std::string and char*, it maps (char*)0 to an empty string...
void merge()
Merges toAdd and ToRemove list to stable list.
including fstream is not hell here because this header only included by implementation file...
std::set< PoolQuery > LockSet
ResStatus & status() const
Returns the current status.
void writePoolQueriesToFile(const zypp::filesystem::Pathname &file, InputIterator begin, InputIterator end)
Writes all queries from begin to end.
locks lock same item in pool but his parameters is different
bool setLock(bool toLock_r, TransactByValue causer_r)
Apply a lock (prevent transaction).
static const SolvAttr name
LocksCleanPredicate(size_t count, callback::SendReport< CleanEmptyLocksReport > &_report)
bool mergeList(callback::SendReport< SavingLocksReport > &report)
const_iterator end() const
void save(const Pathname &file=ZConfig::instance().locksFile())
Merges toAdd and ToRemove list to stable list and save that stable list to file.
void readAndApply(const Pathname &file=ZConfig::instance().locksFile())
Optimalized version of read and apply.
void remove_if(LockSet &lockset_r, TPredicate pred_r)
const LockList & APIlocks() const
bool operator()(const PoolQuery &q)
bool empty() const
Whether the result is empty.
void setMatchExact()
Set to match exact string instead of substring.
Helper that splits an identifier into kind and name or vice versa.
Reference to a PoolItem connecting ResObject and ResStatus.
const_iterator begin() const
Query result accessers.
ConflictState
type of conflict of old and new lock
int contains(const PoolQuery &q, std::set< sat::Solvable > &s)
callback::SendReport< SavingLocksReport > & report
void read(const Pathname &file=ZConfig::instance().locksFile())
Read locks from file to list of stable locks (locks which is not changed during session) ...
void removeLock(const PoolQuery &query)
unlocks by result of query and add to toRemove.
callback::SendReport< CleanEmptyLocksReport > & report
const_iterator end() const
An iterator pointing to the end of the query result.
LockList::const_iterator const_iterator
std::set< sat::Solvable > & solvs
bool existEmpty() const
Gets true if some lock doesn't lock any object in pool This can happen e.g.
iterator that takes lock, lock all solvables from query and send query to output iterator ...