From 188a6fcf4f13df1fd362a0aff27a23493ddd1ec5 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 8 Sep 2015 22:14:11 +0200 Subject: implement autobit and pinning in EDSP solver 'apt' The parser creates a preferences as well as an extended states file based on the EDSP scenario file, which isn't the most efficient way of dealing with this as thes text files have to be parsed again by another layer of the code, but it needs the least changes and works good enough for now. The 'apt' solver is in the end just a test solver like dump. --- apt-pkg/edsp/edsplistparser.cc | 50 ++++++++++++++++++++++++++++++++++++++---- apt-pkg/edsp/edsplistparser.h | 3 ++- apt-pkg/edsp/edspsystem.cc | 46 ++++++++++++++++++++++++++++++++++++-- apt-pkg/edsp/edspsystem.h | 3 ++- apt-pkg/policy.cc | 3 ++- 5 files changed, 96 insertions(+), 9 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/edsp/edsplistparser.cc b/apt-pkg/edsp/edsplistparser.cc index ff79b537e..5c90cf1fc 100644 --- a/apt-pkg/edsp/edsplistparser.cc +++ b/apt-pkg/edsp/edsplistparser.cc @@ -11,18 +11,40 @@ // Include Files /*{{{*/ #include +#include #include #include #include #include #include #include +#include /*}}}*/ +class edspListParserPrivate /*{{{*/ +{ +public: + FileFd extendedstates; + FileFd preferences; + + edspListParserPrivate() + { + std::string const states = _config->FindFile("Dir::State::extended_states"); + if (states != "/dev/null") + unlink(states.c_str()); + extendedstates.Open(states, FileFd::WriteOnly | FileFd::Create | FileFd::Exclusive, 0600); + std::string const prefs = _config->FindFile("Dir::Etc::preferences"); + if (prefs != "/dev/null") + unlink(prefs.c_str()); + preferences.Open(prefs, FileFd::WriteOnly | FileFd::Create | FileFd::Exclusive, 0600); + } +}; + /*}}}*/ // ListParser::edspListParser - Constructor /*{{{*/ -edspListParser::edspListParser(FileFd *File) : debListParser(File), d(NULL) -{} +edspListParser::edspListParser(FileFd *File) : debListParser(File), d(new edspListParserPrivate()) +{ +} /*}}}*/ // ListParser::NewVersion - Fill in the version structure /*{{{*/ bool edspListParser::NewVersion(pkgCache::VerIterator &Ver) @@ -81,6 +103,23 @@ bool edspListParser::ParseStatus(pkgCache::PkgIterator &Pkg, Pkg->CurrentVer = Ver.Index(); } + if (Section.FindB("APT-Automatic", false)) + { + std::string out; + strprintf(out, "Package: %s\nArchitecture: %s\nAuto-Installed: 1\n\n", Pkg.Name(), Pkg.Arch()); + if (d->extendedstates.Write(out.c_str(), out.length()) == false) + return false; + } + + signed short const pinvalue = Section.FindI("APT-Pin", 500); + if (pinvalue != 500) + { + std::string out; + strprintf(out, "Package: %s\nPin: version %s\nPin-Priority: %d\n\n", Pkg.FullName().c_str(), Ver.VerStr(), pinvalue); + if (d->preferences.Write(out.c_str(), out.length()) == false) + return false; + } + return true; } /*}}}*/ @@ -91,5 +130,8 @@ APT_CONST bool edspListParser::LoadReleaseInfo(pkgCache::RlsFileIterator & /*Fil return true; } /*}}}*/ - -edspListParser::~edspListParser() {} +edspListParser::~edspListParser() /*{{{*/ +{ + delete d; +} + /*}}}*/ diff --git a/apt-pkg/edsp/edsplistparser.h b/apt-pkg/edsp/edsplistparser.h index 221229302..25363e1c7 100644 --- a/apt-pkg/edsp/edsplistparser.h +++ b/apt-pkg/edsp/edsplistparser.h @@ -24,10 +24,11 @@ #endif class FileFd; +class edspListParserPrivate; class APT_HIDDEN edspListParser : public debListParser { - void * const d; + edspListParserPrivate * const d; public: virtual bool NewVersion(pkgCache::VerIterator &Ver) APT_OVERRIDE; virtual std::string Description(); diff --git a/apt-pkg/edsp/edspsystem.cc b/apt-pkg/edsp/edspsystem.cc index f577efcbd..c52d537f3 100644 --- a/apt-pkg/edsp/edspsystem.cc +++ b/apt-pkg/edsp/edspsystem.cc @@ -17,15 +17,55 @@ #include #include #include +#include #include +#include + #include #include /*}}}*/ +class edspSystemPrivate { + std::string tempDir; + std::string tempStatesFile; + std::string tempPrefsFile; + +public: + edspSystemPrivate() {} + + void Initialize(Configuration &Cnf) + { + DeInitialize(); + Cnf.Set("Dir::State::extended_states", "/dev/null"); + Cnf.Set("Dir::Etc::preferences", "/dev/null"); + std::string const tmp = GetTempDir(); + char tmpname[100]; + snprintf(tmpname, sizeof(tmpname), "%s/apt-edsp-solver-XXXXXX", tmp.c_str()); + if (NULL == mkdtemp(tmpname)) + return; + tempDir = tmpname; + tempStatesFile = flCombine(tempDir, "extended_states"); + Cnf.Set("Dir::State::extended_states", tempStatesFile); + tempPrefsFile = flCombine(tempDir, "apt_preferences"); + Cnf.Set("Dir::Etc::preferences", tempPrefsFile); + } + + void DeInitialize() + { + if (tempDir.empty()) + return; + + unlink(tempStatesFile.c_str()); + unlink(tempPrefsFile.c_str()); + rmdir(tempDir.c_str()); + } + + ~edspSystemPrivate() { DeInitialize(); } +}; // System::edspSystem - Constructor /*{{{*/ -edspSystem::edspSystem() : pkgSystem("Debian APT solver interface", &debVS), d(NULL), StatusFile(NULL) +edspSystem::edspSystem() : pkgSystem("Debian APT solver interface", &debVS), d(new edspSystemPrivate()), StatusFile(NULL) { } /*}}}*/ @@ -33,6 +73,7 @@ edspSystem::edspSystem() : pkgSystem("Debian APT solver interface", &debVS), d(N edspSystem::~edspSystem() { delete StatusFile; + delete d; } /*}}}*/ // System::Lock - Get the lock /*{{{*/ @@ -59,7 +100,8 @@ pkgPackageManager *edspSystem::CreatePM(pkgDepCache * /*Cache*/) const // System::Initialize - Setup the configuration space.. /*{{{*/ bool edspSystem::Initialize(Configuration &Cnf) { - Cnf.Set("Dir::State::extended_states", "/dev/null"); + d->Initialize(Cnf); + Cnf.Set("Dir::Etc::preferencesparts", "/dev/null"); Cnf.Set("Dir::State::status","/dev/null"); Cnf.Set("Dir::State::lists","/dev/null"); diff --git a/apt-pkg/edsp/edspsystem.h b/apt-pkg/edsp/edspsystem.h index ec42bef75..aa4298f01 100644 --- a/apt-pkg/edsp/edspsystem.h +++ b/apt-pkg/edsp/edspsystem.h @@ -24,10 +24,11 @@ class pkgIndexFile; class pkgPackageManager; class edspIndex; +class edspSystemPrivate; class APT_HIDDEN edspSystem : public pkgSystem { /** \brief dpointer placeholder (for later in case we need it) */ - void * const d; + edspSystemPrivate * const d; edspIndex *StatusFile; diff --git a/apt-pkg/policy.cc b/apt-pkg/policy.cc index a1e903178..8441bc465 100644 --- a/apt-pkg/policy.cc +++ b/apt-pkg/policy.cc @@ -409,7 +409,8 @@ bool ReadPinDir(pkgPolicy &Plcy,string Dir) if (DirectoryExists(Dir) == false) { - _error->WarningE("DirectoryExists",_("Unable to read %s"),Dir.c_str()); + if (Dir != "/dev/null") + _error->WarningE("DirectoryExists",_("Unable to read %s"),Dir.c_str()); return true; } -- cgit v1.2.3-70-g09d2