libzypp  13.10.6
ZYppImpl.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
13 #include <iostream>
14 #include "zypp/TmpPath.h"
15 #include "zypp/base/Logger.h"
16 #include "zypp/base/String.h"
17 
20 #include "zypp/target/TargetImpl.h"
21 #include "zypp/ZYpp.h"
22 #include "zypp/DiskUsageCounter.h"
23 #include "zypp/ZConfig.h"
24 #include "zypp/sat/Pool.h"
25 #include "zypp/PoolItem.h"
26 
27 using std::endl;
28 
30 namespace zypp
31 {
32  namespace zypp_detail
34  {
35 
37  //
38  // METHOD NAME : ZYppImpl::ZYppImpl
39  // METHOD TYPE : Constructor
40  //
42  : _target(0)
43  , _resolver( new Resolver( ResPool::instance()) )
44  {
46  MIL << "Initializing keyring..." << std::endl;
47  _keyring = new KeyRing(tmpPath());
48  }
49 
51  //
52  // METHOD NAME : ZYppImpl::~ZYppImpl
53  // METHOD TYPE : Destructor
54  //
56  {}
57 
58  //------------------------------------------------------------------------
59  // add/remove resolvables
60 
62  {
63  if ( ! _disk_usage )
64  {
66  }
67  return _disk_usage->disk_usage(pool());
68  }
69 
71  {
72  _disk_usage.reset(new DiskUsageCounter());
73  _disk_usage->setMountPoints(mp);
74  }
75 
77  {
78  if (_disk_usage)
79  return _disk_usage->getMountPoints();
80  else
82  }
83 
84  //------------------------------------------------------------------------
85  // target
86 
87  Target_Ptr ZYppImpl::target() const
88  {
89  if (! _target)
90  ZYPP_THROW(Exception("Target not initialized."));
91  return _target;
92  }
93 
94  void ZYppImpl::initializeTarget( const Pathname & root, bool doRebuild_r )
95  {
96  MIL << "initTarget( " << root << (doRebuild_r?", rebuilddb":"") << ")" << endl;
97  if (_target) {
98  if (_target->root() == root) {
99  MIL << "Repeated call to initializeTarget()" << endl;
100  return;
101  }
102 
103  _target->unload();
104 
105  }
106  _target = new Target( root, doRebuild_r );
107  _target->buildCache();
108  }
109 
111  {
112  if (_target)
113  _target->unload();
114 
115  _target = 0;
116  }
117 
118  //------------------------------------------------------------------------
119  // commit
120 
124  {
125  setenv( "ZYPP_IS_RUNNING", str::numstring(getpid()).c_str(), 1 );
126 
127  if ( getenv("ZYPP_TESTSUITE_FAKE_ARCH") )
128  {
129  ZYPP_THROW( Exception("ZYPP_TESTSUITE_FAKE_ARCH set. Commit not allowed and disabled.") );
130  }
131 
132  MIL << "Attempt to commit (" << policy_r << ")" << endl;
133  if (! _target)
134  ZYPP_THROW( Exception("Target not initialized.") );
135 
136  ZYppCommitResult res = _target->_pimpl->commit( pool(), policy_r );
137 
138  if (! policy_r.dryRun() )
139  {
140  if ( policy_r.syncPoolAfterCommit() )
141  {
142  // reload new status from target
143  DBG << "reloading " << sat::Pool::instance().systemRepoAlias() << " repo to pool" << endl;
144  _target->load();
145  }
146  else
147  {
148  DBG << "unloading " << sat::Pool::instance().systemRepoAlias() << " repo from pool" << endl;
149  _target->unload();
150  }
151  }
152 
153  MIL << "Commit (" << policy_r << ") returned: "
154  << res << endl;
155  return res;
156  }
157 
158  void ZYppImpl::installSrcPackage( const SrcPackage_constPtr & srcPackage_r )
159  {
160  if (! _target)
161  ZYPP_THROW( Exception("Target not initialized.") );
162  _target->_pimpl->installSrcPackage( srcPackage_r );
163  }
164 
165  ManagedFile ZYppImpl::provideSrcPackage( const SrcPackage_constPtr & srcPackage_r )
166  {
167  if (! _target)
168  ZYPP_THROW( Exception("Target not initialized.") );
169  return _target->_pimpl->provideSrcPackage( srcPackage_r );
170  }
171 
172  //------------------------------------------------------------------------
173  // target store path
174 
175  Pathname ZYppImpl::homePath() const
176  { return _home_path.empty() ? Pathname("/var/lib/zypp") : _home_path; }
177 
178  void ZYppImpl::setHomePath( const Pathname & path )
179  { _home_path = path; }
180 
181  Pathname ZYppImpl::tmpPath() const
182  {
183  static TmpDir zypp_tmp_dir( TmpPath::defaultLocation(), "zypp." );
184  return zypp_tmp_dir.path();
185  }
186 
187  /******************************************************************
188  **
189  ** FUNCTION NAME : operator<<
190  ** FUNCTION TYPE : std::ostream &
191  */
192  std::ostream & operator<<( std::ostream & str, const ZYppImpl & obj )
193  {
194  return str << "ZYppImpl";
195  }
196 
198  } // namespace zypp_detail
201 } // namespace zypp
#define MIL
Definition: Logger.h:47
void setHomePath(const Pathname &path)
set the home, if you need to change it
Definition: ZYppImpl.cc:178
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:320
Result returned from ZYpp::commit.
static ZConfig & instance()
Singleton ctor.
Definition: ZConfig.cc:655
Pathname path() const
Definition: TmpPath.cc:146
std::ostream & about(std::ostream &str) const
Print some detail about the current libzypp version.
Definition: ZConfig.cc:961
Gpg key handling.
Definition: KeyRing.h:132
Pathname tmpPath() const
Get the path where zypp related plugins store tmp data.
Definition: ZYppImpl.cc:181
ZYppCommitPolicy & dryRun(bool yesNo_r)
Set dry run (default: false).
Target_Ptr target() const
Definition: ZYppImpl.cc:87
DiskUsageCounter::MountPointSet diskUsage()
Definition: ZYppImpl.cc:61
void initializeTarget(const Pathname &root, bool doRebuild_r)
Definition: ZYppImpl.cc:94
std::set< MountPoint > MountPointSet
shared_ptr< DiskUsageCounter > _disk_usage
defined mount points, used for disk usage counting
Definition: ZYppImpl.h:124
ZYppCommitResult commit(const ZYppCommitPolicy &policy_r)
Commit changes and transactions.
Definition: ZYppImpl.cc:123
static Pool instance()
Singleton ctor.
Definition: Pool.h:51
Dependency resolver interface.
Definition: Resolver.h:47
Provide a new empty temporary directory and recursively delete it when no longer needed.
Definition: TmpPath.h:170
static const std::string & systemRepoAlias()
Reserved system repository alias .
Definition: Pool.cc:33
ZYppImpl()
Default ctor.
Definition: ZYppImpl.cc:41
Options and policies for ZYpp::commit.
void installSrcPackage(const SrcPackage_constPtr &srcPackage_r)
Install a source package on the Target.
Definition: ZYppImpl.cc:158
ZYppCommitPolicy & syncPoolAfterCommit(bool yesNo_r)
Kepp pool in sync with the Target databases after commit (default: true)
std::string numstring(char n, int w=0)
Definition: String.h:219
std::ostream & operator<<(std::ostream &str, const ZYppImpl &obj)
Definition: ZYppImpl.cc:192
Global ResObject pool.
Definition: ResPool.h:48
Base class for Exception.
Definition: Exception.h:143
DiskUsageCounter::MountPointSet getPartitions() const
Definition: ZYppImpl.cc:76
Reference counted access to a _Tp object calling a custom Dispose function when the last AutoDispose ...
Definition: AutoDispose.h:92
Pathname homePath() const
Get the path where zypp related plugins store persistent data and caches.
Definition: ZYppImpl.cc:175
ResPool pool() const
Definition: ZYppImpl.h:52
void setPartitions(const DiskUsageCounter::MountPointSet &mp)
Definition: ZYppImpl.cc:70
ManagedFile provideSrcPackage(const SrcPackage_constPtr &srcPackage_r)
Install a source package on the Target.
Definition: ZYppImpl.cc:165
#define DBG
Definition: Logger.h:46
static MountPointSet detectMountPoints(const std::string &rootdir="/")