1
/* rpackagestatus.cc - wrapper for accessing packagestatus information
3
* Copyright (c) 2000-2003 Conectiva S/A
4
* 2002-2008 Michael Vogt <mvo@debian.org>
6
* Author: Alfredo K. Kojima <kojima@conectiva.com.br>
7
* Michael Vogt <mvo@debian.org>
9
* Portions Taken from Gnome APT
10
* Copyright (C) 1998 Havoc Pennington <hp@pobox.com>
13
* This program is free software; you can redistribute it and/or
14
* modify it under the terms of the GNU General Public License as
15
* published by the Free Software Foundation; either version 2 of the
16
* License, or (at your option) any later version.
18
* This program is distributed in the hope that it will be useful,
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
* GNU General Public License for more details.
23
* You should have received a copy of the GNU General Public License
24
* along with this program; if not, write to the Free Software
25
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
29
#include <apt-pkg/tagfile.h>
30
#include <apt-pkg/strutl.h>
31
#include "rpackagestatus.h"
33
// init the static release array so that we need to
34
// run lsb_release only once
35
char RPackageStatus::release[255] = {0,};
37
// class that finds out what do display to get user
38
void RPackageStatus::init()
40
const char *status_short[N_STATUS_COUNT] = {
41
"install", "reinstall", "upgrade", "downgrade", "remove",
42
"purge", "available", "available-locked",
43
"installed-updated", "installed-outdated", "installed-locked",
46
memcpy(PackageStatusShortString, status_short, sizeof(status_short));
48
const char *status_long[N_STATUS_COUNT] = {
49
_("Marked for installation"),
50
_("Marked for re-installation"),
51
_("Marked for upgrade"),
52
_("Marked for downgrade"),
53
_("Marked for removal"),
54
_("Marked for complete removal"),
56
_("Not installed (locked)"),
58
_("Installed (upgradable)"),
59
_("Installed (locked to the current version)"),
61
_("Not installed (new in repository)")
63
memcpy(PackageStatusLongString, status_long, sizeof(status_long));
66
// check for unsupported stuff
67
if(_config->FindB("Synaptic::mark-unsupported", true)) {
68
string s, labels, origin, components;
69
markUnsupported = true;
71
// read supported labels
72
labels = _config->Find("Synaptic::supported-label", "Debian Debian-Security");
73
stringstream sst1(labels);
76
supportedLabels.push_back(s);
79
// read supported origins
80
origin = _config->Find("Synaptic::supported-origins", "Debian");
81
stringstream sst2(origin);
84
supportedOrigins.push_back(s);
87
// read supported components
88
components = _config->Find("Synaptic::supported-components", "main updates/main");
89
stringstream sst3(components);
92
supportedComponents.push_back(s);
96
// init the static release once
97
FILE *fp = popen("lsb_release -c -s","r");
99
fgets((char *)RPackageStatus::release, 255, fp);
105
bool RPackageStatus::isSupported(RPackage *pkg)
109
if(markUnsupported) {
114
string component = pkg->component();
115
string label = pkg->label();
116
string origin = pkg->origin();
118
for(unsigned int i=0;i<supportedComponents.size();i++) {
119
if(supportedComponents[i] == component) {
124
for(unsigned int i=0;i<supportedLabels.size();i++) {
125
if(supportedLabels[i] == label) {
130
for(unsigned int i=0;i<supportedOrigins.size();i++) {
131
if(supportedOrigins[i] == origin) {
137
res = (sc & sl & so & pkg->isTrusted());
143
int RPackageStatus::getStatus(RPackage *pkg)
145
int flags = pkg->getFlags();
146
int ret = NotInstalled;
148
if (pkg->wouldBreak()) {
150
} else if (flags & RPackage::FNewInstall) {
152
} else if (flags & RPackage::FUpgrade) {
154
} else if (flags & RPackage::FReInstall) {
156
} else if (flags & RPackage::FDowngrade) {
158
} else if (flags & RPackage::FPurge) {
160
} else if (flags & RPackage::FRemove) {
162
} else if (flags & RPackage::FInstalled) {
163
if (flags & RPackage::FPinned)
164
ret = InstalledLocked;
165
else if (flags & RPackage::FOutdated)
166
ret = InstalledOutdated;
168
ret = InstalledUpdated;
170
if (flags & RPackage::FPinned)
171
ret = NotInstalledLocked;
172
else if (flags & RPackage::FNew)
181
bool RPackageStatus::maintenanceEndTime(RPackage *pkg, struct tm *res)
183
//cerr << "RPackageStatus::maintenanceEndTime()" << std::endl;
186
time_t release_date = -1;
188
string distro = _config->Find("Synaptic::supported-label");
189
string releaseFile = pkg->getReleaseFileForOrigin(distro, release);
190
if(!FileExists(releaseFile)) {
191
// happens e.g. when there is no release file and is harmless
192
//cerr << "mainenanceEndTime(): can not find file: " << releaseFile << endl;
196
// read the relase file
197
FileFd fd(releaseFile, FileFd::ReadOnly);
201
// get the time_t form the string
202
if(!StrToTime(sec.FindS("Date"), release_date))
205
// if its not a supported package, return 0
206
if(!isSupported(pkg))
209
// now calculate the time until there is support
210
gmtime_r(&release_date, res);
212
const int support_time =_config->FindI("Synaptic::supported-month", 0);
213
if (support_time <= 0)
216
res->tm_year += (support_time / 12) + ((res->tm_mon + support_time % 12) / 12);
217
res->tm_mon = (res->tm_mon + support_time) % 12;