summaryrefslogtreecommitdiff
path: root/backends/aptcc/apt-intf.h
blob: bbebbfd4d00b1040719a4bd61086559fee58a1ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/* apt-intf.h - Interface to APT
 *
 * Copyright (c) 1999-2002, 2004-2005, 2007-2008 Daniel Burrows
 * Copyright (c) 2009 Daniel Nicoletti <dantti85-pk@yahoo.com.br>
 *               2012 Matthias Klumpp <matthias@tenstral.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifndef APTINTF_H
#define APTINTF_H

#include <glib.h>
#include <glib/gstdio.h>

#include <pk-backend.h>

#include "AptCacheFile.h"

#define PREUPGRADE_BINARY    "/usr/bin/do-release-upgrade"
#define GDEBI_BINARY         "/usr/bin/gdebi"
#define REBOOT_REQUIRED      "/var/run/reboot-required"

using namespace std;

typedef vector<pkgCache::VerIterator> PkgList;

class pkgProblemResolver;
class Matcher;
class AptIntf
{
public:
    AptIntf(PkBackend *backend, bool &cancel);
    ~AptIntf();

    bool init();
    void cancel();

    /**
     * Tries to find a package with the given packageId
     * @returns pkgCache::VerIterator, if .end() is true the package could not be found
     */
    pkgCache::VerIterator findPackageId(const gchar *packageId);

    /**
     * Tries to find the current version of a package
     * if it can't find it will return the candidate
     * TODO check if we really need the candidate version
     * @returns pkgCache::VerIterator, if .end() is true the version could not be found
     */
    pkgCache::VerIterator findVer(const pkgCache::PkgIterator &pkg);

    /**
     * Tries to find a list of packages mathing the package ids
     * @returns a list of pkgCache::VerIterator, if the list is empty no package was found
     */
    PkgList resolvePackageIds(gchar **package_ids, PkBitfield filters = PK_FILTER_ENUM_NONE);

    /**
      * Refreshes the sources of packages
      */
    void refreshCache();

    /**
      * Tries to resolve a pkg file installation of the given \sa file
      * @param install is where the packages to be installed will be stored
      * @param remove is where the packages to be removed will be stored
      * @returns true if the package can be installed
      */
    bool markFileForInstall(const gchar *file, PkgList &install, PkgList &remove);

    /**
      * Marks the given packages as auto installed
      */
    void markAutoInstalled(AptCacheFile &cache, const PkgList &pkgs);

    /**
     *  runs a transaction to install/remove/update packages
     *  - for install and update, \p remove should be set to false
     *  - if you are going to remove, \p remove should be true
     *  - if you don't want to actually install/update/remove
     *    \p simulate should be true, in this case packages with
     *    what's going to happen will be emitted.
     */
    bool runTransaction(const PkgList &install,
                        const PkgList &remove,
                        bool simulate,
                        bool markAuto,
                        bool fixBroken);

    /**
     *  Get package depends
     */
    void getDepends(PkgList &output,
                    const pkgCache::VerIterator &ver,
                    bool recursive);

    /**
     *  Get package requires
     */
    void getRequires(PkgList &output,
                     const pkgCache::VerIterator &ver,
                     bool recursive);

    /**
      * Returns a list of all packages in the cache
      */
    PkgList getPackages();

    /**
      * Returns a list of all packages in the given groups
      */
    PkgList getPackagesFromGroup(gchar **values);

    /**
      * Returns a list of all packages that matched their names with matcher
      */
    PkgList searchPackageName(Matcher *matcher);

    /**
      * Returns a list of all packages that matched their description with matcher
      */
    PkgList searchPackageDetails(Matcher *matcher);

    /**
      * Returns a list of all packages that matched contains the given files
      */
    PkgList searchPackageFiles(gchar **values);

    /**
     *  Emits a package with the given state
     */
    void emitPackage(const pkgCache::VerIterator &ver, PkInfoEnum state = PK_INFO_ENUM_UNKNOWN);

    /**
      * Emits a list of packages that matches the given filters
      */
    void emitPackages(PkgList &output,
                      PkBitfield filters = PK_FILTER_ENUM_NONE,
                      PkInfoEnum state = PK_INFO_ENUM_UNKNOWN);

    void emitRequireRestart(PkgList &output);

    /**
      * Emits a list of updates that matches the given filters
      */
    void emitUpdates(PkgList &output, PkBitfield filters = PK_FILTER_ENUM_NONE);

    /**
      * Checks if a given package matches the filters
      * @returns true if it passed the filters
      */
    bool matchPackage(const pkgCache::VerIterator &ver, PkBitfield filters);

    /**
      * Returns the list of packages with the ones that passed the given filters
      */
    PkgList filterPackages(const PkgList &packages, PkBitfield filters);

    /**
      * Emits details of the given package
      */
    void emitPackageDetail(const pkgCache::VerIterator &ver);

    /**
      * Emits details of the given package list
      */
    void emitDetails(PkgList &pkgs);

    /**
      * Emits update detail
      */
    void emitUpdateDetail(const pkgCache::VerIterator &candver);

    /**
      * Emits update datails for the given list
      */
    void emitUpdateDetails(const PkgList &pkgs);

    /**
      *  Emits the files of a package
      */
    void emitPackageFiles(const gchar *pi);

    /**
      *  Download and install packages
      */
    bool installPackages(AptCacheFile &cache, bool simulating);

    /**
     *  Install a DEB file
     *
     *  If you don't want to actually install/update/remove
     *    \p simulate should be true, in this case packages with
     *    what's going to happen will be emitted.
     */
    bool installFile(const gchar *path, bool simulate);

    /**
     *  Check which package provides the codec
     */
    void providesCodec(PkgList &output, gchar **values);

    /**
     *  Check which package provides a shared library
     */
    void providesLibrary(PkgList &output, gchar **values);

    /**
     *  returns a list of packages names
     */
    void providesMimeType(PkgList &output, gchar **values);

    /** Like pkgAcqArchive, but uses generic File objects to download to
     *  the cwd (and copies from file:/ URLs).
     */
    bool getArchive(pkgAcquire *Owner, pkgCache::VerIterator const &Version,
                    std::string directory, std::string &StoreFilename);

private:
    bool checkTrusted(pkgAcquire &fetcher, bool simulating);
    bool packageIsSupported(const pkgCache::VerIterator &verIter, string component);
    void tryToRemove(const pkgCache::VerIterator &ver,
                     pkgDepCache &Cache,
                     pkgProblemResolver &Fix);
    bool tryToInstall(const pkgCache::VerIterator &ver,
                      pkgDepCache &Cache,
                      pkgProblemResolver &Fix,
                      bool BrokenFix,
                      unsigned int &ExpectedInst);

    /**
     *  interprets dpkg status fd
     */
    void updateInterface(int readFd, int writeFd);
    bool doAutomaticRemove(AptCacheFile &cache);
    bool removingEssentialPackages(AptCacheFile &cache);
    PkgList checkChangedPackages(AptCacheFile &cache, bool emitChanged);
    void emitTransactionPackage(string name, PkInfoEnum state);

    AptCacheFile m_cache;
    PkBackend  *m_backend;
    bool       &m_cancel;
    struct stat m_restartStat;

    bool m_isMultiArch;
    PkgList m_pkgs;
    PkgList m_restartPackages;

    time_t     m_lastTermAction;
    string     m_lastPackage;
    uint       m_lastSubProgress;
    bool       m_startCounting;

    // when the internal terminal timesout after no activity
    int m_terminalTimeout;
    pid_t m_child_pid;
};

#endif