Imported Upstream version 16.4.0
[platform/upstream/libzypp.git] / zypp / target / TargetImpl.h
index d2221eb..6658900 100644 (file)
 #define ZYPP_TARGET_TARGETIMPL_H
 
 #include <iosfwd>
-#include <list>
 #include <set>
 
 #include "zypp/base/ReferenceCounted.h"
 #include "zypp/base/NonCopyable.h"
-#include "zypp/base/DefaultFalseBool.h"
 #include "zypp/base/PtrTypes.h"
 #include "zypp/PoolItem.h"
 #include "zypp/ZYppCommit.h"
@@ -29,8 +27,9 @@
 #include "zypp/target/rpm/RpmDb.h"
 #include "zypp/target/TargetException.h"
 #include "zypp/target/RequestedLocalesFile.h"
-#include "zypp/target/SoftLocksFile.h"
+#include "zypp/target/SolvIdentFile.h"
 #include "zypp/target/HardLocksFile.h"
+#include "zypp/ManagedFile.h"
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
@@ -40,6 +39,7 @@ namespace zypp
   { /////////////////////////////////////////////////////////////////
 
     DEFINE_PTR_TYPE(TargetImpl);
+    class CommitPackageCache;
 
     ///////////////////////////////////////////////////////////////////
     //
@@ -67,10 +67,7 @@ namespace zypp
       /** Dtor. */
       virtual ~TargetImpl();
 
-      /** Null implementation */
-      static TargetImpl_Ptr nullimpl();
-
-      /** 
+      /**
        * generates the unique anonymous id which is called
        * when creating the target
        */
@@ -79,17 +76,39 @@ namespace zypp
       /**
        * generates a cache of the last product flavor
        */
-      void createLastBaseProductFlavorCache() const;
+      void createLastDistributionFlavorCache() const;
+
+      /** \name Solv file handling.
+       * If target solv file is outdated, but (non-root-)user has
+       * no permission to  create it at the default location, we
+       * use a temporary one.
+       */
+      //@{
+    private:
+      /** The systems default solv file location. */
+      Pathname defaultSolvfilesPath() const;
+
+      /** The solv file location actually in use (default or temp). */
+      Pathname solvfilesPath() const
+      { return solvfilesPathIsTemp() ? _tmpSolvfilesPath : defaultSolvfilesPath(); }
+
+      /** Whether we're using a temp. solvfile. */
+      bool solvfilesPathIsTemp() const
+      { return ! _tmpSolvfilesPath.empty(); }
 
-      void load();
+      Pathname _tmpSolvfilesPath;
+
+    public:
+      void load( bool force = true );
 
       void unload();
 
+      void reload();
+
       void clearCache();
 
-      void buildCache();
-
-      std::string anonymousUniqueId() const;
+      bool buildCache();
+      //@}
 
     public:
 
@@ -99,35 +118,20 @@ namespace zypp
 
       /** The directory to store things. */
       Pathname home() const
-      { return _root / "/var/lib/zypp"; }
+      { return home( _root ); }
+
+      static Pathname home( const Pathname & root_r )
+      { return root_r / "/var/lib/zypp"; }
 
       /** Commit changes in the pool */
       ZYppCommitResult commit( ResPool pool_r, const ZYppCommitPolicy & policy_r );
 
-      ZYPP_DEPRECATED int commit( ResPool pool_r, unsigned int medianr,
-                                  PoolItemList & errors_r,
-                                  PoolItemList & remaining_r,
-                                  PoolItemList & srcremaining_r,
-                                  bool dry_run = false )
-      {
-        ZYppCommitPolicy policy;
-        policy.restrictToMedia( medianr ).dryRun( dry_run );
-        ZYppCommitResult res = commit( pool_r, policy );
-        errors_r.swap( res._errors );
-        remaining_r.swap( res._remaining );
-        srcremaining_r.swap( res._srcremaining );
-        return res._result;
-      }
-
-      /** Commit ordered changes
-       *  @param pool_r only needed for #160792
-       *  @return uncommitted ones (due to error)
-       */
-      PoolItemList commit( const PoolItemList & items_r, const ZYppCommitPolicy & policy_r, const ResPool & pool_r );
-
       /** Install a source package on the Target. */
       void installSrcPackage( const SrcPackage_constPtr & srcPackage_r );
 
+      /** Provides a source package on the Target. */
+      ManagedFile provideSrcPackage( const SrcPackage_constPtr & srcPackage_r );
+
       /** Overload to realize stream output. */
       virtual std::ostream & dumpOn( std::ostream & str ) const
       {
@@ -152,18 +156,58 @@ namespace zypp
       /** \copydoc Target::baseProduct() */
       Product::constPtr baseProduct() const;
 
-      /** \copydoc Target::release() */
-      std::string release() const;
+      /** \copydoc Target::requestedLocales() */
+      LocaleSet requestedLocales() const
+      { return _requestedLocalesFile.locales(); }
+      /** \overload */
+      static LocaleSet requestedLocales( const Pathname & root_r );
+
+      /** \copydoc Target::updateAutoInstalled */
+      void updateAutoInstalled();
 
       /** \copydoc Target::targetDistribution() */
       std::string targetDistribution() const;
+      /** \overload */
+      static std::string targetDistribution( const Pathname & root_r );
 
       /** \copydoc Target::targetDistributionRelease()*/
       std::string targetDistributionRelease() const;
+      /** \overload */
+      static std::string targetDistributionRelease( const Pathname & root_r );
+
+      /** \copydoc Target::targetDistributionFlavor()*/
+      std::string targetDistributionFlavor() const;
+      /** \overload */
+      static std::string targetDistributionFlavor( const Pathname & root_r );
+
+      /** \copydoc Target::distributionLabel()*/
+      Target::DistributionLabel distributionLabel() const;
+      /** \overload */
+      static Target::DistributionLabel distributionLabel( const Pathname & root_r );
 
       /** \copydoc Target::distributionVersion()*/
       std::string distributionVersion() const;
+      /** \overload */
+      static std::string distributionVersion( const Pathname & root_r );
+
+      /** \copydoc Target::distributionFlavor() */
+      std::string distributionFlavor() const;
+      /** \overload */
+      static std::string distributionFlavor( const Pathname & root_r );
+
+      /** \copydoc Target::anonymousUniqueId() */
+      std::string anonymousUniqueId() const;
+      /** \overload */
+      static std::string anonymousUniqueId( const Pathname & root_r );
 
+    private:
+      /** Commit ordered changes (internal helper) */
+      void commit( const ZYppCommitPolicy & policy_r,
+                  CommitPackageCache & packageCache_r,
+                  ZYppCommitResult & result_r );
+
+      /** Commit helper checking for file conflicts after download. */
+      void commitFindFileConflicts( const ZYppCommitPolicy & policy_r, ZYppCommitResult & result_r );
     protected:
       /** Path to the target */
       Pathname _root;
@@ -171,15 +215,12 @@ namespace zypp
       rpm::RpmDb _rpm;
       /** Requested Locales database */
       RequestedLocalesFile _requestedLocalesFile;
-      /** Soft-locks database */
-      SoftLocksFile _softLocksFile;
+      /** user/auto installed database */
+      SolvIdentFile _autoInstalledFile;
       /** Hard-Locks database */
       HardLocksFile _hardLocksFile;
       /** Cache distributionVersion */
       mutable std::string _distributionVersion;
-    private:
-      /** Null implementation */
-      static TargetImpl_Ptr _nullimpl;
     };
     ///////////////////////////////////////////////////////////////////