]> git.saurik.com Git - apt.git/blame - apt-pkg/edsp/edsplistparser.cc
edsp: use an ID mapping for the internal solver
[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
6d38011b
DK
24 /*}}}*/
25
188a6fcf
DK
26class edspListParserPrivate /*{{{*/
27{
28public:
29 FileFd extendedstates;
30 FileFd preferences;
31
32 edspListParserPrivate()
33 {
34 std::string const states = _config->FindFile("Dir::State::extended_states");
ce1f3a2c 35 RemoveFile("edspListParserPrivate", states);
188a6fcf
DK
36 extendedstates.Open(states, FileFd::WriteOnly | FileFd::Create | FileFd::Exclusive, 0600);
37 std::string const prefs = _config->FindFile("Dir::Etc::preferences");
ce1f3a2c 38 RemoveFile("edspListParserPrivate", prefs);
188a6fcf
DK
39 preferences.Open(prefs, FileFd::WriteOnly | FileFd::Create | FileFd::Exclusive, 0600);
40 }
41};
42 /*}}}*/
6d38011b 43// ListParser::edspListParser - Constructor /*{{{*/
188a6fcf
DK
44edspListParser::edspListParser(FileFd *File) : debListParser(File), d(new edspListParserPrivate())
45{
46}
6d38011b
DK
47 /*}}}*/
48// ListParser::NewVersion - Fill in the version structure /*{{{*/
49bool edspListParser::NewVersion(pkgCache::VerIterator &Ver)
50{
307d9eb2 51 _system->SetVersionMapping(Ver->ID, Section.FindI("APT-ID", Ver->ID));
6d38011b
DK
52 return debListParser::NewVersion(Ver);
53}
54 /*}}}*/
55// ListParser::Description - Return the description string /*{{{*/
56// ---------------------------------------------------------------------
57/* Sorry, no description for the resolvers… */
02ceb810 58std::vector<std::string> edspListParser::AvailableDescriptionLanguages()
6d38011b 59{
02ceb810 60 return {};
6d38011b
DK
61}
62MD5SumValue edspListParser::Description_md5()
63{
64 return MD5SumValue("");
65}
66 /*}}}*/
67// ListParser::VersionHash - Compute a unique hash for this version /*{{{*/
68// ---------------------------------------------------------------------
69/* */
70unsigned short edspListParser::VersionHash()
71{
72 if (Section.Exists("APT-Hash") == true)
73 return Section.FindI("APT-Hash");
74 else if (Section.Exists("APT-ID") == true)
75 return Section.FindI("APT-ID");
76 return 0;
77}
78 /*}}}*/
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. */
83bool 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());
105 if (d->extendedstates.Write(out.c_str(), out.length()) == false)
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());
114 if (d->preferences.Write(out.c_str(), out.length()) == false)
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);
123 if (d->preferences.Write(out.c_str(), out.length()) == false)
124 return false;
125 }
126
6d38011b
DK
127 return true;
128}
129 /*}}}*/
130// ListParser::LoadReleaseInfo - Load the release information /*{{{*/
b07aeb1a
DK
131APT_CONST bool edspListParser::LoadReleaseInfo(pkgCache::RlsFileIterator & /*FileI*/,
132 FileFd & /*File*/, std::string const &/*component*/)
6d38011b
DK
133{
134 return true;
135}
136 /*}}}*/
188a6fcf
DK
137edspListParser::~edspListParser() /*{{{*/
138{
139 delete d;
140}
141 /*}}}*/