]> git.saurik.com Git - apt.git/blame - apt-pkg/edsp/edsplistparser.cc
more explicit MarkRequired algorithm code (part 2)
[apt.git] / apt-pkg / edsp / edsplistparser.cc
CommitLineData
6d38011b
DK
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
3/* ######################################################################
4
5 Package Cache Generator - Generator for the cache structure.
6
7 This builds the cache structure from the abstract package list parser.
8
9 ##################################################################### */
10 /*}}}*/
11// Include Files /*{{{*/
ea542140
DK
12#include <config.h>
13
188a6fcf 14#include <apt-pkg/configuration.h>
6d38011b 15#include <apt-pkg/edsplistparser.h>
6d38011b 16#include <apt-pkg/md5.h>
453b82a3
DK
17#include <apt-pkg/deblistparser.h>
18#include <apt-pkg/pkgcache.h>
19#include <apt-pkg/cacheiterators.h>
20#include <apt-pkg/tagfile.h>
188a6fcf 21#include <apt-pkg/fileutl.h>
307d9eb2 22#include <apt-pkg/pkgsystem.h>
453b82a3 23
6d38011b
DK
24 /*}}}*/
25
26// ListParser::edspListParser - Constructor /*{{{*/
d59671c9
DK
27edspLikeListParser::edspLikeListParser(FileFd * const File) : debListParser(File)
28{
29}
30edspListParser::edspListParser(FileFd * const File) : edspLikeListParser(File)
188a6fcf 31{
d59671c9
DK
32 std::string const states = _config->FindFile("Dir::State::extended_states");
33 RemoveFile("edspListParserPrivate", states);
34 extendedstates.Open(states, FileFd::WriteOnly | FileFd::Create | FileFd::Exclusive, 0600);
35 std::string const prefs = _config->FindFile("Dir::Etc::preferences");
36 RemoveFile("edspListParserPrivate", prefs);
37 preferences.Open(prefs, FileFd::WriteOnly | FileFd::Create | FileFd::Exclusive, 0600);
188a6fcf 38}
6d38011b
DK
39 /*}}}*/
40// ListParser::NewVersion - Fill in the version structure /*{{{*/
d59671c9 41bool edspLikeListParser::NewVersion(pkgCache::VerIterator &Ver)
6d38011b 42{
307d9eb2 43 _system->SetVersionMapping(Ver->ID, Section.FindI("APT-ID", Ver->ID));
6d38011b
DK
44 return debListParser::NewVersion(Ver);
45}
46 /*}}}*/
47// ListParser::Description - Return the description string /*{{{*/
48// ---------------------------------------------------------------------
49/* Sorry, no description for the resolvers… */
d59671c9 50std::vector<std::string> edspLikeListParser::AvailableDescriptionLanguages()
6d38011b 51{
02ceb810 52 return {};
6d38011b 53}
d59671c9 54MD5SumValue edspLikeListParser::Description_md5()
6d38011b
DK
55{
56 return MD5SumValue("");
57}
58 /*}}}*/
59// ListParser::VersionHash - Compute a unique hash for this version /*{{{*/
d59671c9 60unsigned short edspLikeListParser::VersionHash()
6d38011b
DK
61{
62 if (Section.Exists("APT-Hash") == true)
63 return Section.FindI("APT-Hash");
64 else if (Section.Exists("APT-ID") == true)
65 return Section.FindI("APT-ID");
66 return 0;
67}
68 /*}}}*/
d59671c9
DK
69// ListParser::LoadReleaseInfo - Load the release information /*{{{*/
70APT_CONST bool edspLikeListParser::LoadReleaseInfo(pkgCache::RlsFileIterator & /*FileI*/,
71 FileFd & /*File*/, std::string const &/*component*/)
72{
73 return true;
74}
75 /*}}}*/
6d38011b
DK
76// ListParser::ParseStatus - Parse the status field /*{{{*/
77// ---------------------------------------------------------------------
78/* The Status: line here is not a normal dpkg one but just one which tells
79 use if the package is installed or not, where missing means not. */
80bool edspListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
81 pkgCache::VerIterator &Ver)
82{
9221da7e
DK
83 unsigned long state = 0;
84 if (Section.FindFlag("Hold",state,pkgCache::State::Hold) == false)
6d38011b 85 return false;
9221da7e
DK
86 if (state != 0)
87 Pkg->SelectedState = pkgCache::State::Hold;
6d38011b 88
9221da7e 89 state = 0;
b195733d
DK
90 if (Section.FindFlag("Installed",state,pkgCache::State::Installed) == false)
91 return false;
92 if (state != 0)
6d38011b 93 {
b195733d
DK
94 Pkg->CurrentState = pkgCache::State::Installed;
95 Pkg->CurrentVer = Ver.Index();
6d38011b 96 }
b195733d 97
188a6fcf
DK
98 if (Section.FindB("APT-Automatic", false))
99 {
100 std::string out;
101 strprintf(out, "Package: %s\nArchitecture: %s\nAuto-Installed: 1\n\n", Pkg.Name(), Pkg.Arch());
d59671c9 102 if (extendedstates.Write(out.c_str(), out.length()) == false)
188a6fcf
DK
103 return false;
104 }
105
294a8020
DK
106 // FIXME: Using an overriding pin is wrong.
107 if (Section.FindB("APT-Candidate", false))
108 {
109 std::string out;
110 strprintf(out, "Package: %s\nPin: version %s\nPin-Priority: 9999\n\n", Pkg.FullName().c_str(), Ver.VerStr());
d59671c9 111 if (preferences.Write(out.c_str(), out.length()) == false)
294a8020
DK
112 return false;
113 }
114
188a6fcf
DK
115 signed short const pinvalue = Section.FindI("APT-Pin", 500);
116 if (pinvalue != 500)
117 {
118 std::string out;
119 strprintf(out, "Package: %s\nPin: version %s\nPin-Priority: %d\n\n", Pkg.FullName().c_str(), Ver.VerStr(), pinvalue);
d59671c9 120 if (preferences.Write(out.c_str(), out.length()) == false)
188a6fcf
DK
121 return false;
122 }
123
6d38011b
DK
124 return true;
125}
126 /*}}}*/
d59671c9 127
f74d99c6
DK
128// ListParser::eippListParser - Constructor /*{{{*/
129eippListParser::eippListParser(FileFd *File) : edspLikeListParser(File)
130{
131}
132 /*}}}*/
133// ListParser::ParseStatus - Parse the status field /*{{{*/
134// ---------------------------------------------------------------------
135/* The Status: line here is not a normal dpkg one but just one which tells
136 use if the package is installed or not, where missing means not. */
137bool eippListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
138 pkgCache::VerIterator &Ver)
139{
140 // Process the flag field
141 static std::array<WordList, 8> const statusvalues = {{
142 {"not-installed",pkgCache::State::NotInstalled},
143 {"config-files",pkgCache::State::ConfigFiles},
144 {"half-installed",pkgCache::State::HalfInstalled},
145 {"unpacked",pkgCache::State::UnPacked},
146 {"half-configured",pkgCache::State::HalfConfigured},
147 {"triggers-awaited",pkgCache::State::TriggersAwaited},
148 {"triggers-pending",pkgCache::State::TriggersPending},
149 {"installed",pkgCache::State::Installed},
150 }};
151 auto const status = Section.Find("Status");
152 if (status.empty() == false)
153 {
154 for (auto && sv: statusvalues)
155 {
156 if (status != sv.Str)
157 continue;
158 Pkg->CurrentState = sv.Val;
159 switch (Pkg->CurrentState)
160 {
161 case pkgCache::State::NotInstalled:
162 case pkgCache::State::ConfigFiles:
163 break;
164 case pkgCache::State::HalfInstalled:
165 case pkgCache::State::UnPacked:
166 case pkgCache::State::HalfConfigured:
167 case pkgCache::State::TriggersAwaited:
168 case pkgCache::State::TriggersPending:
169 case pkgCache::State::Installed:
170 Pkg->CurrentVer = Ver.Index();
171 break;
172 }
173 break;
174 }
175 }
176
177 return true;
178}
179 /*}}}*/
180
d59671c9
DK
181edspLikeListParser::~edspLikeListParser() {}
182edspListParser::~edspListParser() {}
f74d99c6 183eippListParser::~eippListParser() {}