]>
Commit | Line | Data |
---|---|---|
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 | ||
23 | /*}}}*/ | |
24 | ||
25 | class edspListParserPrivate /*{{{*/ | |
26 | { | |
27 | public: | |
28 | FileFd extendedstates; | |
29 | FileFd preferences; | |
30 | ||
31 | edspListParserPrivate() | |
32 | { | |
33 | std::string const states = _config->FindFile("Dir::State::extended_states"); | |
34 | RemoveFile("edspListParserPrivate", states); | |
35 | extendedstates.Open(states, FileFd::WriteOnly | FileFd::Create | FileFd::Exclusive, 0600); | |
36 | std::string const prefs = _config->FindFile("Dir::Etc::preferences"); | |
37 | RemoveFile("edspListParserPrivate", prefs); | |
38 | preferences.Open(prefs, FileFd::WriteOnly | FileFd::Create | FileFd::Exclusive, 0600); | |
39 | } | |
40 | }; | |
41 | /*}}}*/ | |
42 | // ListParser::edspListParser - Constructor /*{{{*/ | |
43 | edspListParser::edspListParser(FileFd *File) : debListParser(File), d(new edspListParserPrivate()) | |
44 | { | |
45 | } | |
46 | /*}}}*/ | |
47 | // ListParser::NewVersion - Fill in the version structure /*{{{*/ | |
48 | bool edspListParser::NewVersion(pkgCache::VerIterator &Ver) | |
49 | { | |
50 | Ver->ID = Section.FindI("APT-ID", Ver->ID); | |
51 | return debListParser::NewVersion(Ver); | |
52 | } | |
53 | /*}}}*/ | |
54 | // ListParser::Description - Return the description string /*{{{*/ | |
55 | // --------------------------------------------------------------------- | |
56 | /* Sorry, no description for the resolvers… */ | |
57 | std::vector<std::string> edspListParser::AvailableDescriptionLanguages() | |
58 | { | |
59 | return {}; | |
60 | } | |
61 | MD5SumValue edspListParser::Description_md5() | |
62 | { | |
63 | return MD5SumValue(""); | |
64 | } | |
65 | /*}}}*/ | |
66 | // ListParser::VersionHash - Compute a unique hash for this version /*{{{*/ | |
67 | // --------------------------------------------------------------------- | |
68 | /* */ | |
69 | unsigned short edspListParser::VersionHash() | |
70 | { | |
71 | if (Section.Exists("APT-Hash") == true) | |
72 | return Section.FindI("APT-Hash"); | |
73 | else if (Section.Exists("APT-ID") == true) | |
74 | return Section.FindI("APT-ID"); | |
75 | return 0; | |
76 | } | |
77 | /*}}}*/ | |
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. */ | |
82 | bool edspListParser::ParseStatus(pkgCache::PkgIterator &Pkg, | |
83 | pkgCache::VerIterator &Ver) | |
84 | { | |
85 | unsigned long state = 0; | |
86 | if (Section.FindFlag("Hold",state,pkgCache::State::Hold) == false) | |
87 | return false; | |
88 | if (state != 0) | |
89 | Pkg->SelectedState = pkgCache::State::Hold; | |
90 | ||
91 | state = 0; | |
92 | if (Section.FindFlag("Installed",state,pkgCache::State::Installed) == false) | |
93 | return false; | |
94 | if (state != 0) | |
95 | { | |
96 | Pkg->CurrentState = pkgCache::State::Installed; | |
97 | Pkg->CurrentVer = Ver.Index(); | |
98 | } | |
99 | ||
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()); | |
104 | if (d->extendedstates.Write(out.c_str(), out.length()) == false) | |
105 | return false; | |
106 | } | |
107 | ||
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()); | |
113 | if (d->preferences.Write(out.c_str(), out.length()) == false) | |
114 | return false; | |
115 | } | |
116 | ||
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); | |
122 | if (d->preferences.Write(out.c_str(), out.length()) == false) | |
123 | return false; | |
124 | } | |
125 | ||
126 | return true; | |
127 | } | |
128 | /*}}}*/ | |
129 | // ListParser::LoadReleaseInfo - Load the release information /*{{{*/ | |
130 | APT_CONST bool edspListParser::LoadReleaseInfo(pkgCache::RlsFileIterator & /*FileI*/, | |
131 | FileFd & /*File*/, std::string const &/*component*/) | |
132 | { | |
133 | return true; | |
134 | } | |
135 | /*}}}*/ | |
136 | edspListParser::~edspListParser() /*{{{*/ | |
137 | { | |
138 | delete d; | |
139 | } | |
140 | /*}}}*/ |