]> git.saurik.com Git - apt.git/blob - apt-pkg/edsp/edsplistparser.cc
doc: Fix fuzzy string regression
[apt.git] / apt-pkg / edsp / edsplistparser.cc
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 /*{{{*/
12 #include <config.h>
13
14 #include <apt-pkg/configuration.h>
15 #include <apt-pkg/edsplistparser.h>
16 #include <apt-pkg/md5.h>
17 #include <apt-pkg/deblistparser.h>
18 #include <apt-pkg/pkgcache.h>
19 #include <apt-pkg/cacheiterators.h>
20 #include <apt-pkg/tagfile.h>
21 #include <apt-pkg/fileutl.h>
22 #include <apt-pkg/pkgsystem.h>
23
24 /*}}}*/
25
26 // ListParser::edspListParser - Constructor /*{{{*/
27 edspLikeListParser::edspLikeListParser(FileFd * const File) : debListParser(File)
28 {
29 }
30 edspListParser::edspListParser(FileFd * const File) : edspLikeListParser(File)
31 {
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);
38 }
39 /*}}}*/
40 // ListParser::NewVersion - Fill in the version structure /*{{{*/
41 bool edspLikeListParser::NewVersion(pkgCache::VerIterator &Ver)
42 {
43 _system->SetVersionMapping(Ver->ID, Section.FindI("APT-ID", Ver->ID));
44 return debListParser::NewVersion(Ver);
45 }
46 /*}}}*/
47 // ListParser::Description - Return the description string /*{{{*/
48 // ---------------------------------------------------------------------
49 /* Sorry, no description for the resolvers… */
50 std::vector<std::string> edspLikeListParser::AvailableDescriptionLanguages()
51 {
52 return {};
53 }
54 MD5SumValue edspLikeListParser::Description_md5()
55 {
56 return MD5SumValue("");
57 }
58 /*}}}*/
59 // ListParser::VersionHash - Compute a unique hash for this version /*{{{*/
60 unsigned short edspLikeListParser::VersionHash()
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 /*}}}*/
69 // ListParser::LoadReleaseInfo - Load the release information /*{{{*/
70 APT_CONST bool edspLikeListParser::LoadReleaseInfo(pkgCache::RlsFileIterator & /*FileI*/,
71 FileFd & /*File*/, std::string const &/*component*/)
72 {
73 return true;
74 }
75 /*}}}*/
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. */
80 bool edspListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
81 pkgCache::VerIterator &Ver)
82 {
83 unsigned long state = 0;
84 if (Section.FindFlag("Hold",state,pkgCache::State::Hold) == false)
85 return false;
86 if (state != 0)
87 Pkg->SelectedState = pkgCache::State::Hold;
88
89 state = 0;
90 if (Section.FindFlag("Installed",state,pkgCache::State::Installed) == false)
91 return false;
92 if (state != 0)
93 {
94 Pkg->CurrentState = pkgCache::State::Installed;
95 Pkg->CurrentVer = Ver.Index();
96 }
97
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());
102 if (extendedstates.Write(out.c_str(), out.length()) == false)
103 return false;
104 }
105
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());
111 if (preferences.Write(out.c_str(), out.length()) == false)
112 return false;
113 }
114
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);
120 if (preferences.Write(out.c_str(), out.length()) == false)
121 return false;
122 }
123
124 return true;
125 }
126 /*}}}*/
127
128 // ListParser::eippListParser - Constructor /*{{{*/
129 eippListParser::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. */
137 bool 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
181 edspLikeListParser::~edspLikeListParser() {}
182 edspListParser::~edspListParser() {}
183 eippListParser::~eippListParser() {}