Go to the documentation of this file.
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(); }
122 DBG <<
"lock "<< item.name();
131 template <
class OutputIterator>
150 MIL <<
"read and apply locks from "<<file << endl;
154 std::insert_iterator<LockSet> ii(
_pimpl->MANIPlocks(),
_pimpl->MANIPlocks().end() );
156 readPoolQueriesFromFile( file, boost::make_function_output_iterator(lout) );
159 MIL <<
"file does not exist(or cannot be stat), no lock added." << endl;
165 MIL <<
"read locks from "<<file << endl;
168 readPoolQueriesFromFile( file, std::insert_iterator<LockSet>(
_pimpl->MANIPlocks(),
_pimpl->MANIPlocks().end()) );
170 MIL <<
"file does not exist(or cannot be stat), no lock added." << endl;
176 DBG <<
"apply locks" << endl;
183 MIL <<
"add new lock" << endl;
189 if (
_pimpl->toRemove.erase( query ) )
191 DBG <<
"query removed from toRemove" << endl;
195 DBG <<
"query added as new" << endl;
196 _pimpl->toAdd.insert( query );
218 DBG <<
"add lock by identifier" << endl;
224 MIL <<
"remove lock" << endl;
231 if (
_pimpl->toAdd.erase( query ) )
233 DBG <<
"query removed from added" << endl;
237 DBG <<
"need to remove some old lock" << endl;
238 _pimpl->toRemove.insert( query );
260 DBG <<
"remove lock by Selectable" << endl;
302 switch (
report->execute(q))
313 INT <<
"Unexpected return value from callback. Need to adapt switch statement." << std::endl;
323 MIL <<
"clean of locks" << endl;
326 size_t sum =
_pimpl->locks().size();
333 MIL <<
"cleaning aborted" << endl;
342 if ( sum !=
_pimpl->locks().size() )
343 _pimpl->locksDirty =
true;
357 bool intersect =
false;
360 if ( s.find(*it)!=s.end() )
370 return intersect ? 1 : 0;
384 DBG <<
"identical queries" << endl;
402 MIL <<
"find conflict: " << cs << endl;
403 switch (
report->conflict(q,cs))
407 DBG <<
"abort merging" << endl;
410 DBG <<
"force delete" << endl;
413 DBG <<
"skip lock" << endl;
416 INT <<
"Unexpected return value from callback. Need to adapt switch statement." << std::endl;
425 MIL <<
"merge list old: " <<
locks().size()
426 <<
" to add: " <<
toAdd.size() <<
"to remove: " <<
toRemove.size() << endl;
429 std::set<sat::Solvable> s(it->begin(),it->end());
446 if( (
_pimpl->toAdd.size() |
_pimpl->toRemove.size())==0)
458 DBG <<
"locks merged" << endl;
460 _pimpl->locksDirty =
true;
465 if( ((
_pimpl->toAdd.size() |
_pimpl->toRemove.size())==0)
468 DBG <<
"nothing changed in locks - no write to file" << endl;
475 if ((
_pimpl->toAdd.size() |
_pimpl->toRemove.size())!=0)
484 DBG <<
"wrote "<<
_pimpl->locks().size() <<
"locks" << endl;
485 writePoolQueriesToFile( file,
_pimpl->locks().begin(),
_pimpl->locks().end() );
bool existEmpty() const
Gets true if some lock doesn't lock any object in pool This can happen e.g.
Combining sat::Solvable and ResStatus.
bool isExist() const
Return whether valid stat info exists.
Singleton class which manipulate with locks file and apply locks on pool.
void addAttribute(const sat::SolvAttr &attr, const std::string &value="")
Filter by the value of the specified attr attribute.
Iterable< PoolItem_iterator > poolItem() const
const_iterator begin() const
void operator()(const PoolQuery &query) const
void setCaseSensitive(bool value=true)
Turn case sentitivity on or off (unsets or sets SEARCH_NOCASE flag).
void operator()(const PoolQuery &query) const
void apply() const
Applies locks in stable list (locks which is not changed during session).
LocksCleanPredicate(size_t count, callback::SendReport< CleanEmptyLocksReport > &_report)
bool operator()(const PoolQuery &q)
void readAndApply(const Pathname &file=ZConfig::instance().locksFile())
Optimalized version of read and apply.
@ IGNORE
skip conflict lock
void addKind(const ResKind &kind)
Filter by selectable kind.
int contains(const PoolQuery &q, std::set< sat::Solvable > &s)
@ INTERSECT
locks lock some file and unlocking lock unlock only part of iti, so removing old lock can unlock more...
void removeEmpty()
Call callback for each empty lock.
callback::SendReport< CleanEmptyLocksReport > & report
void merge()
Merges toAdd and ToRemove list to stable list.
RW_pointer< Impl, rw_pointer::Scoped< Impl > > _pimpl
const LockSet & locks() const
std::string asString() const
Conversion to std::string
Access to the sat-pools string space.
@ DELETE
delete conflicted lock
std::list< PoolQuery > LockList
callback::SendReport< SavingLocksReport > & report
Wrapper class for ::stat/::lstat.
iterator that takes lock, lock all solvables from query and send query to output iterator
@ ABORTED
cleaning aborted by user
void remove_if(LockSet &lockset_r, TPredicate pred_r)
void read(const Pathname &file=ZConfig::instance().locksFile())
Read locks from file to list of stable locks (locks which is not changed during session)
LockList::size_type size() const
static const SolvAttr name
@ SAME_RESULTS
locks lock same item in pool but his parameters is different
bool operator()(const PoolQuery &q)
std::set< sat::Solvable > & solvs
const_iterator end() const
An iterator pointing to the end of the query result.
ConflictState
type of conflict of old and new lock
LocksRemovePredicate(std::set< sat::Solvable > &s, const PoolQuery &q, callback::SendReport< SavingLocksReport > &r)
Easy-to use interface to the ZYPP dependency resolver.
const_iterator begin() const
Query result accessers.
LockList::const_iterator const_iterator
void addLock(const PoolQuery &query)
TODO add: toBeAdded{Begin,End,Size,Empty} toBeRemoved{Begin,End,Size,Empty}.
Convenience char* constructible from std::string and char*, it maps (char*)0 to an empty string.
@ ABORTED
cleaning aborted by user
LockingOutputIterator(OutputIterator &out_)
bool setLock(bool toLock_r, TransactByValue causer_r)
Apply a lock (prevent transaction).
std::set< PoolQuery > LockSet
@ ABORT
abort and return error
@ DELETE
delete empty lock
bool empty() const
Whether the result is empty.
void removeDuplicates()
Delete all query duplicate in loaded locks.
ResStatus & status() const
Returns the current status.
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
const LockList & APIlocks() const
const_iterator end() const
void setMatchExact()
Set to match exact string instead of substring.
void save(const Pathname &file=ZConfig::instance().locksFile())
Merges toAdd and ToRemove list to stable list and save that stable list to file.
static Locks & instance()
Gets instance of this class.
void removeLock(const PoolQuery &query)
unlocks by result of query and add to toRemove.
bool mergeList(callback::SendReport< SavingLocksReport > &report)
@ ABORT
abort and return error
Helper that splits an identifier into kind and name or vice versa.