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;
59 {
return _pimpl->locks.begin(); }
62 {
return _pimpl->locks.end(); }
65 {
return _pimpl->locks.size(); }
68 {
return _pimpl->locks.empty(); }
77 DBG <<
"lock "<< item.name();
86 template <
class OutputIterator>
105 MIL <<
"read and apply locks from "<<file << endl;
106 PathInfo pinfo(file);
107 if ( pinfo.isExist() )
109 std::insert_iterator<LockList> ii(
_pimpl->locks,
_pimpl->locks.end() );
114 MIL <<
"file not exist(or cannot be stat), no lock added." << endl;
120 MIL <<
"read locks from "<<file << endl;
121 PathInfo pinfo(file);
122 if ( pinfo.isExist() )
125 MIL <<
"file not exist(or cannot be stat), no lock added." << endl;
131 DBG <<
"apply locks" << endl;
138 MIL <<
"add new lock" << endl;
144 LockList::iterator i = find(
_pimpl->toRemove.begin(),
145 _pimpl->toRemove.end(), query);
146 if ( i !=
_pimpl->toRemove.end() )
148 DBG <<
"query removed from toRemove" << endl;
149 _pimpl->toRemove.erase(i);
153 DBG <<
"query added as new" << endl;
154 _pimpl->toAdd.push_back( query );
176 DBG <<
"add lock by identifier" << endl;
182 MIL <<
"remove lock" << endl;
189 LockList::iterator i = find(
_pimpl->toAdd.begin(),
190 _pimpl->toAdd.end(), query);
191 if ( i !=
_pimpl->toAdd.end() )
193 DBG <<
"query removed from added" << endl;
198 DBG <<
"needed remove some old lock" << endl;
199 _pimpl->toRemove.push_back( query );
222 DBG <<
"remove lock by selectactable" << endl;
264 switch (
report->execute(q))
275 WAR <<
"Unknown returned value. Callback have more value then"
276 <<
" this switch. Need correct handle all enum values." << std::endl;
286 MIL <<
"cleaning of locks" << endl;
289 size_t sum =
_pimpl->locks.size();
292 _pimpl->locks.remove_if(p);
296 MIL <<
"cleaning aborted" << endl;
305 if ( sum !=
_pimpl->locks.size() )
306 _pimpl->locksDirty =
true;
320 bool intersect =
false;
323 if ( s.find(*it)!=s.end() )
333 return intersect ? 1 : 0;
347 DBG <<
"identical queries" << endl;
365 MIL <<
"find conflict: " << cs << endl;
366 switch (
report->conflict(q,cs))
370 DBG <<
"abort merging" << endl;
373 DBG <<
"force delete" << endl;
376 DBG <<
"skip lock" << endl;
379 WAR <<
"should not reached, some state is missing" << endl;
388 MIL <<
"merging list old: " <<
locks.size()
389 <<
" to add: " <<
toAdd.size() <<
"to remove: " <<
toRemove.size() << endl;
392 std::set<sat::Solvable> s(it->begin(),it->end());
396 if (!report->progress())
402 locks.push_back( *it );
413 if( (
_pimpl->toAdd.size() |
_pimpl->toRemove.size())==0)
420 if (!
_pimpl->mergeList(report))
425 DBG <<
"locks merged" << endl;
427 _pimpl->locksDirty =
true;
432 if( ((
_pimpl->toAdd.size() |
_pimpl->toRemove.size())==0)
435 DBG <<
"nothing changed in locks - no write to file" << endl;
442 if ((
_pimpl->toAdd.size() |
_pimpl->toRemove.size())!=0)
444 if (!
_pimpl->mergeList(report))
451 DBG <<
"writed "<<
_pimpl->locks.size() <<
"locks" << endl;
461 if ( find(
_pimpl->locks.begin(),it,*it) != it )
462 _pimpl->locks.erase(it--);
466 _pimpl->locksDirty =
true;
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
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 requireAll() const
Whether all values added via addString() or addAttribute() are required to match the values of the re...
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
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...
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).
Iterable< PoolItem_iterator > poolItem() const
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.
bool operator()(PoolQuery &q)
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.
Combining sat::Solvable and ResStatus.
LockList::size_type size_type
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 ...