summaryrefslogtreecommitdiff
path: root/src/installtransaction.h
blob: 113abf2872fcb576b672823865aebaeef18625f9 (plain)
    1 ////////////////////////////////////////////////////////////////////////
    2 // FILE:        installtransaction.h
    3 // AUTHOR:      Johannes Winkelmann, jw@tks6.net
    4 // COPYRIGHT:   (c) 2002 by Johannes Winkelmann
    5 // ---------------------------------------------------------------------
    6 //  This program is free software; you can redistribute it and/or modify
    7 //  it under the terms of the GNU General Public License as published by
    8 //  the Free Software Foundation; either version 2 of the License, or
    9 //  (at your option) any later version.
   10 ////////////////////////////////////////////////////////////////////////
   11 
   12 #ifndef _INSTALLTRANSACTION_H_
   13 #define _INSTALLTRANSACTION_H_
   14 
   15 #include <string>
   16 #include <list>
   17 #include <map>
   18 #include <vector>
   19 #include <utility>
   20 using namespace std;
   21 
   22 #include "depresolver.h"
   23 
   24 class Repository;
   25 class PkgDB;
   26 class Package;
   27 class ArgParser;
   28 class Configuration;
   29 /*!
   30   \class InstallTransaction
   31   \brief Transaction for installing/updating a list of packages
   32 */
   33 class InstallTransaction
   34 {
   35 public:
   36     InstallTransaction( const list<char*>& names,
   37                         const Repository* repo,
   38                         PkgDB* pkgDB,
   39                         const Configuration* config );
   40     InstallTransaction( const list<string>& names,
   41                         const Repository* repo,
   42                         PkgDB* pkgDB,
   43                         const Configuration* config );
   44     InstallTransaction( const string& name,
   45                         const Repository* repo,
   46                         PkgDB* pkgDB,
   47                         const Configuration* config );
   48 
   49     static const std::string PKGMK_DEFAULT_COMMAND;
   50     static const std::string PKGADD_DEFAULT_COMMAND;
   51     static const std::string PKGRM_DEFAULT_COMMAND;
   52 
   53 
   54     /*! Result of an installation */
   55     enum InstallResult {
   56         SUCCESS,             /*!< yeah, success */
   57         NO_PACKAGE_GIVEN,    /*!< no package give to install */
   58         PACKAGE_NOT_FOUND,   /*!< package not found */
   59         PKGMK_EXEC_ERROR,    /*!< can't execute pkgmk */
   60         PKGMK_FAILURE,       /*!< error while pkgmk */
   61         PKGADD_EXEC_ERROR,   /*!< can't execute pkgadd */
   62         PKGDEST_ERROR,             /*!< can't change to PKGDEST */
   63         PKGADD_FAILURE,      /*!< error while pkgadd */
   64         CYCLIC_DEPEND,       /*!< cyclic dependencies found */
   65         LOG_DIR_FAILURE,     /*!< couldn't create log directory */
   66         LOG_FILE_FAILURE,    /*!< couldn't create log file */
   67         NO_LOG_FILE,         /*!< no log file specified */
   68         CANT_LOCK_LOG_FILE   /*!< can't create lock for log file */
   69     };
   70 
   71     enum State {
   72         EXEC_SUCCESS,
   73         FAILED,
   74         NONEXISTENT
   75     };
   76     struct InstallInfo {
   77         InstallInfo(bool hasReadme_) {
   78             hasReadme = hasReadme_;
   79             preState = NONEXISTENT;
   80             postState = NONEXISTENT;
   81         }
   82         State preState;
   83         State postState;
   84         bool hasReadme;
   85     };
   86 
   87     InstallResult install( const ArgParser* parser,
   88                            bool update,
   89                            bool group );
   90     InstallResult  calcDependencies();
   91 
   92     const list< pair<string, InstallInfo> >& installedPackages() const;
   93     const list<string>& alreadyInstalledPackages() const;
   94     const list<string>& ignoredPackages() const;
   95 
   96 
   97     const list<string>& dependencies() const;
   98     const list< pair<string,string> >& missing() const;
   99     const list< pair<string, InstallInfo> >& installError() const;
  100 
  101     static string getPkgmkPackageDir();
  102     static string getPkgmkCompressionMode();
  103 
  104 private:
  105     bool calculateDependencies();
  106     void checkDependecies( const Package* package, int depends=-1 );
  107 
  108     InstallResult installPackage( const Package* package,
  109                                   const ArgParser* parser,
  110                                   bool update,
  111                                   InstallInfo& info ) const;
  112 
  113     static string getPkgmkSetting(const string& setting);
  114     static string getPkgmkSettingFromFile(const string& setting, 
  115                                           const string& fileName);
  116 
  117     PkgDB* m_pkgDB;
  118     DepResolver m_resolver;
  119     const Repository* m_repo;
  120 
  121     // packages to be installed
  122     list< pair<string, const Package*> > m_packages;
  123 
  124     // boolean used to implement lazy initialization
  125     bool m_depCalced;
  126 
  127     // packages< pair<name, hasReadme> > installed by this transaction
  128     list< pair<string, InstallInfo> > m_installedPackages;
  129 
  130     // packages which were requested to be installed which where already
  131     list<string> m_alreadyInstalledPackages;
  132 
  133     // packages which are required by the transaction, but ignored by
  134     // the user
  135     list<string> m_ignoredPackages;
  136 
  137     list<string> m_depNameList;
  138     vector<string> m_depList;
  139 
  140     // packages requested to be installed not found in the ports tree
  141     list< pair<string, string> > m_missingPackages;
  142 
  143     // packages where build/installed failed
  144     list< pair<string, InstallInfo> > m_installErrors;
  145 
  146     /// prt-get itself
  147     const Configuration* m_config;
  148 
  149 };
  150 
  151 #endif /* _INSTALLTRANSACTION_H_ */

Generated by cgit