SET( zypp_target_SRCS
target/RpmPostTransCollector.cc
target/RequestedLocalesFile.cc
- target/SoftLocksFile.cc
target/HardLocksFile.cc
target/CommitPackageCache.cc
target/CommitPackageCacheImpl.cc
SET( zypp_target_HEADERS
target/RpmPostTransCollector.h
target/RequestedLocalesFile.h
- target/SoftLocksFile.h
target/HardLocksFile.h
target/CommitPackageCache.h
target/CommitPackageCacheImpl.h
Repository ResPool::reposFind( const std::string & alias_r ) const
{ return _pimpl->reposFind( alias_r ); }
-#ifdef WITHSOFTLOCKS
- bool ResPool::autoSoftLocksEmpty() const
- { return _pimpl->autoSoftLocks().empty(); }
-
- ResPool::size_type ResPool::autoSoftLocksSize() const
- { return _pimpl->autoSoftLocks().size(); }
-
- ResPool::autoSoftLocks_iterator ResPool::autoSoftLocksBegin() const
- { return _pimpl->autoSoftLocks().begin(); }
-
- ResPool::autoSoftLocks_iterator ResPool::autoSoftLocksEnd() const
- { return _pimpl->autoSoftLocks().end(); }
-
- void ResPool::setAutoSoftLocks( const AutoSoftLocks & newLocks_r )
- { _pimpl->setAutoSoftLocks( newLocks_r ); }
-
- void ResPool::getActiveSoftLocks( AutoSoftLocks & activeLocks_r )
- { _pimpl->getActiveSoftLocks( activeLocks_r ); }
-#endif
-
bool ResPool::hardLockQueriesEmpty() const
{ return _pimpl->hardLockQueries().empty(); }
bool isAvailableLocale( const Locale & locale_r ) const;
//@}
-#ifdef WITHSOFTLOCKS
- public:
- /** \name Handle automatic soft-locks.
- *
- * Solvables with and ident listed here are per default created with
- * a setSoftLock applied. I.e. the \ref Resolver should not automatically
- * select them, if they are just recommended.
- *
- * This list is considered when adding new repos to the pool. It is
- * \b not the list of currently softLocked items.
- *
- * Mainly used to re-apply soft-locks remembered during the last commit.
- */
- //@{
- typedef pool::PoolTraits::AutoSoftLocks AutoSoftLocks;
- typedef pool::PoolTraits::autoSoftLocks_iterator autoSoftLocks_iterator;
-
- bool autoSoftLocksEmpty() const;
- size_type autoSoftLocksSize() const;
- autoSoftLocks_iterator autoSoftLocksBegin() const;
- autoSoftLocks_iterator autoSoftLocksEnd() const;
-
- /** Set a new soft-lock list.
- * The soft-locks of existing PoolItems are adjusted according
- * to the list. (usually called on target load)
- */
- void setAutoSoftLocks( const AutoSoftLocks & newLocks_r );
-
- /** Suggest a new soft-lock list based on the current selection.
- * Based on the the current soft-lock list. Items tagged to be
- * installed are removed, and those tagged to be deleted are added.
- * (usually remembered on commit).
- */
- void getActiveSoftLocks( AutoSoftLocks & activeLocks_r );
- //@}
-#endif
public:
/** \name Handle hard locks (e.g set from /etc/zypp/locks).
*
return setChanged;
}
-#ifdef WITHSOFTLOCKS
- public:
- typedef PoolTraits::AutoSoftLocks AutoSoftLocks;
- typedef PoolTraits::autoSoftLocks_iterator autoSoftLocks_iterator;
-
- const AutoSoftLocks & autoSoftLocks() const
- { return _autoSoftLocks; }
-
- bool autoSoftLockAppliesTo( sat::Solvable solv_r ) const
- { return( _autoSoftLocks.find( solv_r.ident() ) != _autoSoftLocks.end() ); }
-
- void setAutoSoftLocks( const AutoSoftLocks & newLocks_r )
- {
- MIL << "Apply " << newLocks_r.size() << " AutoSoftLocks: " << newLocks_r << endl;
- _autoSoftLocks = newLocks_r;
- // now adjust the pool status
- for_( it, begin(), end() )
- {
- if ( ! it->status().isKept() )
- continue;
-
- if ( autoSoftLockAppliesTo( it->satSolvable() ) )
- it->status().setSoftLock( ResStatus::USER );
- else
- it->status().resetTransact( ResStatus::USER );
- }
- }
-
- void getActiveSoftLocks( AutoSoftLocks & activeLocks_r )
- {
- activeLocks_r = _autoSoftLocks; // current soft-locks
- AutoSoftLocks todel; // + names to be deleted
- AutoSoftLocks toins; // - names to be installed
-
- for_( it, begin(), end() )
- {
- ResStatus & status( it->status() );
- if ( ! ( status.isByUser() || status.isByApplLow() ) )
- continue; // ignore non-user requests; ApplLow means selected
- // by solver, but on behalf of a user request.
-
- switch ( status.getTransactValue() )
- {
- case ResStatus::KEEP_STATE:
- // Filter only items included in the last recommended set.
- if ( status.isRecommended() )
- activeLocks_r.insert( it->satSolvable().ident() );
- break;
- case ResStatus::LOCKED:
- // NOOP
- break;
- case ResStatus::TRANSACT:
- (status.isInstalled() ? todel : toins).insert( it->satSolvable().ident() );
- break;
- }
- }
- for_( it, todel.begin(), todel.end() )
- {
- activeLocks_r.insert( *it );
- }
- for_( it, toins.begin(), toins.end() )
- {
- activeLocks_r.erase( *it );
- }
- }
-#endif
public:
const ContainerT & store() const
{
// remember products for buddy processing (requires clean store)
if ( s.isKind( ResKind::product ) )
addedProducts.push_back( pi );
-#ifdef WITHSOFTLOCKS
- // and on the fly check for weak locks...
- if ( autoSoftLockAppliesTo( s ) )
- {
- pi.status().setSoftLock( ResStatus::USER );
- }
-#endif
if ( !addedItems )
addedItems = true;
}
mutable shared_ptr<ResPoolProxy> _poolProxy;
private:
-#ifdef WITHSOFTLOCKS
- /** Set of solvable idents that should be soft locked per default. */
- AutoSoftLocks _autoSoftLocks;
-#endif
/** Set of queries that define hardlocks. */
HardLockQueries _hardLockQueries;
};
/** list of known Repositories */
typedef sat::Pool::RepositoryIterator repository_iterator;
-#ifdef WITHSOFTLOCKS
- /** soft locks */
- typedef std::tr1::unordered_set<IdString> AutoSoftLocks;
- typedef AutoSoftLocks::const_iterator autoSoftLocks_iterator;
-#endif
-
/** hard locks from etc/zypp/locks */
typedef std::list<PoolQuery> HardLockQueries;
typedef HardLockQueries::const_iterator hardLockQueries_iterator;
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/target/SoftLocksFile.cc
- *
-*/
-#include <iostream>
-#include <fstream>
-
-#include "zypp/base/LogTools.h"
-#include "zypp/base/IOStream.h"
-#include "zypp/base/String.h"
-
-#include "zypp/PathInfo.h"
-#include "zypp/TmpPath.h"
-#include "zypp/Date.h"
-
-#include "zypp/target/SoftLocksFile.h"
-
-using std::endl;
-
-///////////////////////////////////////////////////////////////////
-namespace zypp
-{ /////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////
- namespace target
- { /////////////////////////////////////////////////////////////////
-
- void SoftLocksFile::load( const Pathname & file_r, Data & data_r )
- {
- PathInfo pi( file_r );
- if ( ! pi.isFile() )
- {
- WAR << "Can't read " << pi << endl;
- return;
- }
- std::ifstream infile( file_r.c_str() );
- for( iostr::EachLine in( infile ); in; in.next() )
- {
- std::string l( str::trim(*in) );
- if ( ! l.empty() && l[0] != '#' )
- {
- data_r.insert( IdString(l) );
- }
- }
- MIL << "Read " << pi << endl;
- }
-
- void SoftLocksFile::store( const Pathname & file_r, const Data & data_r )
- {
- filesystem::TmpFile tmp( filesystem::TmpFile::makeSibling( file_r ) );
- filesystem::chmod( tmp.path(), 0644 );
-
- std::ofstream outs( tmp.path().c_str() );
- outs << "# zypp::SoftLocksFile generated " << Date::now() << endl;
- dumpRange( outs, data_r.begin(), data_r.end(), "#", "\n", "\n", "\n", "#\n" );
- outs.close();
-
- if ( outs.good() )
- {
- filesystem::rename( tmp.path(), file_r );
- MIL << "Wrote " << PathInfo(file_r) << endl;
- }
- else
- {
- ERR << "Can't write " << PathInfo(tmp.path()) << endl;
- }
- }
-
- /******************************************************************
- **
- ** FUNCTION NAME : operator<<
- ** FUNCTION TYPE : std::ostream &
- */
- std::ostream & operator<<( std::ostream & str, const SoftLocksFile & obj )
- {
- str << obj.file() << ' ';
- if ( obj._dataPtr )
- str << obj.data();
- else
- str << "(unloaded)";
- return str;
- }
-
- /////////////////////////////////////////////////////////////////
- } // namespace target
- ///////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
-} // namespace zypp
-///////////////////////////////////////////////////////////////////
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/target/SoftLocksFile.h
- *
-*/
-#ifndef ZYPP_TARGET_SOFTLOCKSFILE_H
-#define ZYPP_TARGET_SOFTLOCKSFILE_H
-
-#include <iosfwd>
-
-#include "zypp/base/PtrTypes.h"
-
-#include "zypp/IdString.h"
-#include "zypp/Pathname.h"
-
-///////////////////////////////////////////////////////////////////
-namespace zypp
-{ /////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////
- namespace target
- { /////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : SoftLocksFile
- //
- /** Save and restore soft locks.
- */
- class SoftLocksFile
- {
- friend std::ostream & operator<<( std::ostream & str, const SoftLocksFile & obj );
- public:
- typedef std::tr1::unordered_set<IdString> Data;
-
- public:
- /** Ctor taking the file to read/write. */
- SoftLocksFile( const Pathname & file_r )
- : _file( file_r )
- {}
-
- /** Return the file path. */
- const Pathname & file() const
- { return _file; }
-
- /** Return the data.
- * The file is read once on demand. Returns empty \ref Data if
- * the file does not exist or is not readable.
- */
- const Data & data() const
- {
- if ( !_dataPtr )
- {
- _dataPtr.reset( new Data );
- Data & mydata( *_dataPtr );
- load( _file, mydata );
- }
- return *_dataPtr;
- }
-
- /** Store new \ref Data.
- * Write the new \ref Data to file, unless we know it
- * did not change. The directory containing file must
- * exist.
- */
- void setData( const Data & data_r )
- {
- if ( !_dataPtr )
- _dataPtr.reset( new Data );
-
- if ( differs( *_dataPtr, data_r ) )
- {
- store( _file, data_r );
- *_dataPtr = data_r;
- }
- }
-
- private:
- /** Helper testing whether two \ref Data differ. */
- bool differs( const Data & lhs, const Data & rhs ) const
- {
-
- if ( lhs.size() != rhs.size() )
- return true;
- for_( it, lhs.begin(), lhs.end() )
- {
- if ( rhs.find( *it ) == rhs.end() )
- return true;
- }
- return false;
- }
- /** Read \ref Data from \c file_r. */
- static void load( const Pathname & file_r, Data & data_r );
- /** Write \ref Data to \c file_r. */
- static void store( const Pathname & file_r, const Data & data_r );
-
- private:
- Pathname _file;
- mutable scoped_ptr<Data> _dataPtr;
- };
- ///////////////////////////////////////////////////////////////////
-
- /** \relates SoftLocksFile Stream output */
- std::ostream & operator<<( std::ostream & str, const SoftLocksFile & obj );
-
- /////////////////////////////////////////////////////////////////
- } // namespace target
- ///////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
-} // namespace zypp
-///////////////////////////////////////////////////////////////////
-#endif // ZYPP_TARGET_SOFTLOCKSFILE_H
TargetImpl::TargetImpl( const Pathname & root_r, bool doRebuild_r )
: _root( root_r )
, _requestedLocalesFile( home() / "RequestedLocales" )
- , _softLocksFile( home() / "SoftLocks" )
, _hardLocksFile( Pathname::assertprefix( _root, ZConfig::instance().locksFile() ) )
{
_rpm.initDatabase( root_r, Pathname(), doRebuild_r );
satpool.setRequestedLocales( requestedLocales );
}
}
-#ifdef WITHSOFTLOCKS
{
- SoftLocksFile::Data softLocks( _softLocksFile.data() );
- if ( ! softLocks.empty() )
- {
- // Don't soft lock any installed item.
- for_( it, system.solvablesBegin(), system.solvablesEnd() )
- {
- softLocks.erase( it->ident() );
- }
- ResPool::instance().setAutoSoftLocks( softLocks );
- }
}
-#endif
if ( ZConfig::instance().apply_locks_file() )
{
const HardLocksFile::Data & hardLocks( _hardLocksFile.data() );
filesystem::assert_dir( home() );
// requested locales
_requestedLocalesFile.setLocales( pool_r.getRequestedLocales() );
-#ifdef WITHSOFTLOCKS
- // weak locks
{
- SoftLocksFile::Data newdata;
- pool_r.getActiveSoftLocks( newdata );
- _softLocksFile.setData( newdata );
}
-#endif
// hard locks
if ( ZConfig::instance().apply_locks_file() )
{
#include "zypp/target/rpm/RpmDb.h"
#include "zypp/target/TargetException.h"
#include "zypp/target/RequestedLocalesFile.h"
-#include "zypp/target/SoftLocksFile.h"
#include "zypp/target/HardLocksFile.h"
#include "zypp/ManagedFile.h"
rpm::RpmDb _rpm;
/** Requested Locales database */
RequestedLocalesFile _requestedLocalesFile;
- /** Soft-locks database */
- SoftLocksFile _softLocksFile;
/** Hard-Locks database */
HardLocksFile _hardLocksFile;
/** Cache distributionVersion */