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 string pkgDest() const;
102
103 private:
104 bool calculateDependencies();
105 void checkDependecies( const Package* package, int depends=-1 );
106
107 InstallResult installPackage( const Package* package,
108 const ArgParser* parser,
109 bool update,
110 InstallInfo& info ) const;
111
112 string getPkgDest() const;
113 static string getPkgDestFromFile(const string& fileName);
114
115 PkgDB* m_pkgDB;
116 DepResolver m_resolver;
117 const Repository* m_repo;
118
119 // packages to be installed
120 list< pair<string, const Package*> > m_packages;
121
122 // boolean used to implement lazy initialization
123 bool m_depCalced;
124
125 // packages< pair<name, hasReadme> > installed by this transaction
126 list< pair<string, InstallInfo> > m_installedPackages;
127
128 // packages which were requested to be installed which where already
129 list<string> m_alreadyInstalledPackages;
130
131 // packages which are required by the transaction, but ignored by
132 // the user
133 list<string> m_ignoredPackages;
134
135 list<string> m_depNameList;
136 vector<string> m_depList;
137
138 // field for error messages
139 mutable string m_pkgDest;
140
141 // packages requested to be installed not found in the ports tree
142 list< pair<string, string> > m_missingPackages;
143
144 // packages where build/installed failed
145 list< pair<string, InstallInfo> > m_installErrors;
146
147 /// prt-get itself
148 const Configuration* m_config;
149
150 };
151
152 #endif /* _INSTALLTRANSACTION_H_ */
|