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