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
// class that finds out what do display to get user
34
void RPackageStatus::init()
36
const char *status_short[N_STATUS_COUNT] = {
37
"install", "reinstall", "upgrade", "downgrade", "remove",
38
"purge", "available", "available-locked",
39
"installed-updated", "installed-outdated", "installed-locked",
42
memcpy(PackageStatusShortString, status_short, sizeof(status_short));
44
const char *status_long[N_STATUS_COUNT] = {
45
_("Marked for installation"),
46
_("Marked for re-installation"),
47
_("Marked for upgrade"),
48
_("Marked for downgrade"),
49
_("Marked for removal"),
50
_("Marked for complete removal"),
52
_("Not installed (locked)"),
54
_("Installed (upgradable)"),
55
_("Installed (locked to the current version)"),
57
_("Not installed (new in repository)")
59
memcpy(PackageStatusLongString, status_long, sizeof(status_long));
62
// check for unsupported stuff
63
if(_config->FindB("Synaptic::mark-unsupported",true)) {
64
string s, labels, components;
65
markUnsupported = true;
67
// read supported labels
68
labels = _config->Find("Synaptic::supported-label", "Debian Debian-Security");
69
stringstream sst1(labels);
72
supportedLabels.push_back(s);
75
// read supported components
76
components = _config->Find("Synaptic::supported-components", "main updates/main");
77
stringstream sst2(components);
80
supportedComponents.push_back(s);
86
bool RPackageStatus::isSupported(RPackage *pkg)
95
string component = pkg->component();
96
string label = pkg->label();
98
for(unsigned int i=0;i<supportedComponents.size();i++) {
99
if(supportedComponents[i] == component) {
104
for(unsigned int i=0;i<supportedLabels.size();i++) {
105
if(supportedLabels[i] == label) {
110
res = (sc & sl & pkg->isTrusted());
116
int RPackageStatus::getStatus(RPackage *pkg)
118
int flags = pkg->getFlags();
119
int ret = NotInstalled;
121
if (pkg->wouldBreak()) {
123
} else if (flags & RPackage::FNewInstall) {
125
} else if (flags & RPackage::FUpgrade) {
127
} else if (flags & RPackage::FReInstall) {
129
} else if (flags & RPackage::FDowngrade) {
131
} else if (flags & RPackage::FPurge) {
133
} else if (flags & RPackage::FRemove) {
135
} else if (flags & RPackage::FInstalled) {
136
if (flags & RPackage::FPinned)
137
ret = InstalledLocked;
138
else if (flags & RPackage::FOutdated)
139
ret = InstalledOutdated;
141
ret = InstalledUpdated;
143
if (flags & RPackage::FPinned)
144
ret = NotInstalledLocked;
145
else if (flags & RPackage::FNew)
154
bool RPackageStatus::maintenanceEndTime(RPackage *pkg, struct tm *res)
157
time_t release_date = -1;
159
string releaseFile = pkg->getCandidateReleaseFile();
160
if(!FileExists(releaseFile)) {
161
cerr << "mainenanceEndTime(): can not find " << releaseFile << endl;
165
// read the relase file
166
FileFd fd(releaseFile, FileFd::ReadOnly);
171
// get the time_t form the string
172
if(!StrToTime(sec.FindS("Date"), release_date))
175
// if its not a supported package, return 0
176
if(!isSupported(pkg))
179
// now calculate the time until there is support
180
gmtime_r(&release_date, res);
182
const int support_time =_config->FindI("Synaptic::supported-month", 0);
183
if (support_time <= 0)
186
res->tm_year += (support_time / 12) + ((res->tm_mon + support_time % 12) / 12);
187
res->tm_mon = (res->tm_mon + support_time) % 12;