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"
34 using namespace zypp::str;
41 static Locks _instance;
58 Locks::Locks() : _pimpl(new
Impl){}
61 {
return _pimpl->locks.begin(); }
64 {
return _pimpl->locks.end(); }
67 {
return _pimpl->locks.size(); }
70 {
return _pimpl->locks.empty(); }
89 template <
class OutputIterator>
108 MIL <<
"read and apply locks from "<<file << endl;
109 PathInfo pinfo(file);
110 if ( pinfo.isExist() )
112 insert_iterator<LockList> ii(
_pimpl->locks,
118 MIL <<
"file not exist(or cannot be stat), no lock added." << endl;
124 MIL <<
"read locks from "<<file << endl;
125 PathInfo pinfo(file);
126 if ( pinfo.isExist() )
128 file, insert_iterator<LockList>(
_pimpl->locks,
_pimpl->locks.end()) );
130 MIL <<
"file not exist(or cannot be stat), no lock added." << endl;
136 DBG <<
"apply locks" << endl;
143 MIL <<
"add new lock" << endl;
149 LockList::iterator i = find(
_pimpl->toRemove.begin(),
150 _pimpl->toRemove.end(), query);
151 if ( i !=
_pimpl->toRemove.end() )
153 DBG <<
"query removed from toRemove" << endl;
154 _pimpl->toRemove.erase(i);
158 DBG <<
"query added as new" << endl;
159 _pimpl->toAdd.push_back( query );
181 DBG <<
"add lock by identifier" << endl;
187 MIL <<
"remove lock" << endl;
194 LockList::iterator i = find(
_pimpl->toAdd.begin(),
195 _pimpl->toAdd.end(), query);
196 if ( i !=
_pimpl->toAdd.end() )
198 DBG <<
"query removed from added" << endl;
203 DBG <<
"needed remove some old lock" << endl;
204 _pimpl->toRemove.push_back( query );
226 DBG <<
"remove lock by Selectable" << endl;
268 switch (
report->execute(q))
279 WAR <<
"Unknown returned value. Callback have more value then"
280 <<
" this switch. Need correct handle all enum values." << std::endl;
290 MIL <<
"cleaning of locks" << endl;
293 size_t sum =
_pimpl->locks.size();
296 _pimpl->locks.remove_if(p);
300 MIL <<
"cleaning aborted" << endl;
309 if ( sum !=
_pimpl->locks.size() )
310 _pimpl->locksDirty =
true;
324 bool intersect =
false;
327 if ( s.find(*it)!=s.end() )
337 return intersect ? 1 : 0;
351 DBG <<
"identical queries" << endl;
369 MIL <<
"find conflict: " << cs << endl;
370 switch (
report->conflict(q,cs))
374 DBG <<
"abort merging" << endl;
377 DBG <<
"force delete" << endl;
380 DBG <<
"skip lock" << endl;
383 WAR <<
"should not reached, some state is missing" << endl;
392 MIL <<
"merging list old: " <<
locks.size()
393 <<
" to add: " <<
toAdd.size() <<
"to remove: " <<
toRemove.size() << endl;
396 std::set<sat::Solvable> s(it->begin(),it->end());
400 if (!report->progress())
406 locks.push_back( *it );
417 if( (
_pimpl->toAdd.size() |
_pimpl->toRemove.size())==0)
424 if (!
_pimpl->mergeList(report))
429 DBG <<
"locks merged" << endl;
431 _pimpl->locksDirty =
true;
436 if( ((
_pimpl->toAdd.size() |
_pimpl->toRemove.size())==0)
439 DBG <<
"nothing changed in locks - no write to file" << endl;
446 if ((
_pimpl->toAdd.size() |
_pimpl->toRemove.size())!=0)
448 if (!
_pimpl->mergeList(report))
455 DBG <<
"writed "<<
_pimpl->locks.size() <<
"locks" << endl;
465 if ( find(
_pimpl->locks.begin(),it,*it) != it )
466 _pimpl->locks.erase(it--);
470 _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
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.
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).
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.
Reference to a PoolItem connecting ResObject 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 ...