]> git.saurik.com Git - apt.git/blob - apt-pkg/edsp/edsplistparser.cc
refactor EDSP classes for better internal reuse
[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 edspLikeListParser::~edspLikeListParser() {}
129 edspListParser::~edspListParser() {}