File: apt-cache-file.h

package info (click to toggle)
packagekit 1.3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,704 kB
  • sloc: ansic: 56,209; cpp: 13,919; python: 4,970; xml: 4,945; sh: 313; perl: 60; makefile: 57
file content (197 lines) | stat: -rw-r--r-- 5,616 bytes parent folder | download
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
/* apt-cache-file.h
 *
 * Copyright (c) 2012 Daniel Nicoletti <dantti12@gmail.com>
 * Copyright (c) 2012 Matthias Klumpp <matthias@tenstral.net>
 * Copyright (c) 2016 Harald Sitter <sitter@kde.org>
 *
 * 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 APT_CACHE_FILE_H
#define APT_CACHE_FILE_H

#include <apt-pkg/cachefile.h>
#include <apt-pkg/pkgrecords.h>
#include <apt-pkg/progress.h>
#include <pk-backend.h>

#include "pkg-list.h"

class pkgProblemResolver;
class AptCacheFile : public pkgCacheFile
{
public:
    AptCacheFile(PkBackendJob *job);
    ~AptCacheFile();

    /**
     * Inits the package cache returning false if it can't open
     */
    bool Open(bool withLock = false);

    /**
     * Closes the package cache
     */
    void Close();

    /**
     * Build caches
     */
    bool BuildCaches(bool withLock = false);

    /**
     * This routine generates the caches and then opens the dependency cache
     * and verifies that the system is OK.
     * @param AllowBroken when true it will try to perform the instalation
     * even if we have broken packages, when false it will try to fix
     * the current situation
     */
    bool CheckDeps(bool AllowBroken = false);

    /**
     * Mark Cache for dist-upgrade
     */
    bool DistUpgrade();

    /** Shows a list of all broken packages together with their
     *  dependencies.  Similar to and based on the equivalent routine in
     *  apt-get.
     */
    void ShowBroken(bool Now, PkErrorEnum error = PK_ERROR_ENUM_DEP_RESOLUTION_FAILED);

    inline pkgRecords *GetPkgRecords()
    {
        buildPkgRecords();
        return m_packageRecords;
    }

    /**
     * GetPolicy will build the policy object if needed and return it
     * @note This override if because the cache should be built before the policy
     */
    inline pkgPolicy *GetPolicy()
    {
        BuildCaches();
        BuildPolicy();
        return Policy;
    }

    /**
     * GetDepCache will build the dependency cache if needed and return it
     * @note This override if because the policy should be built before the dependency cache
     */
    inline pkgDepCache *GetDepCache()
    {
        BuildCaches();
        BuildPolicy();
        BuildDepCache();
        return DCache;
    }

    /**
     * Checks if the package is garbage (not depended on)
     */
    bool isGarbage(const pkgCache::PkgIterator &pkg);

    /**
     * DoAutomaticRemove - Remove all automatic unused packages
     *
     * Remove unused automatic packages
     */
    bool doAutomaticRemove();

    /**
     * Checks if there are Essential packages marked to be removed
     */
    bool isRemovingEssentialPackages();

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

    /**
     * Build a package id from the given package version
     * The caller must g_free the returned value
     */
    gchar *buildPackageId(const pkgCache::VerIterator &ver);

    /**
     * Tries to find the candidate version of a package
     * @returns pkgCache::VerIterator, if .end() is true the version could not be found
     */
    pkgCache::VerIterator findCandidateVer(const pkgCache::PkgIterator &pkg);

    /**
     * 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);

    /** \return a short description string corresponding to the given
     *  version.
     */
    std::string getShortDescription(const pkgCache::VerIterator &ver);

    /** \return a short description string corresponding to the given
     *  version.
     */
    std::string getLongDescription(const pkgCache::VerIterator &ver);

    /** \return a short description string corresponding to the given
     *  version.
     */
    std::string getLongDescriptionParsed(const pkgCache::VerIterator &ver);

    bool tryToInstall(
        pkgProblemResolver &Fix,
        const PkgInfo &pki,
        bool autoInst,
        bool preserveAuto,
        bool fixBroken = false);

    void tryToRemove(pkgProblemResolver &Fix, const PkgInfo &pki);

private:
    void buildPkgRecords();
    static std::string debParser(std::string descr);

    pkgRecords *m_packageRecords;
    PkBackendJob *m_job;
};

/**
 * This class is maent to show Operation Progress using PackageKit
 */
class OpPackageKitProgress : public OpProgress
{
public:
    OpPackageKitProgress(PkBackendJob *job);
    virtual ~OpPackageKitProgress();

    virtual void Done();

protected:
    virtual void Update();

private:
    PkBackendJob *m_job;
};

#endif // APT_CACHE_FILE_H