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