Browse Source

refactor EDSP classes for better internal reuse

The classes are all marked as hidden, so changing them is no problem ABI
wise and will help with introducing protocols similar to EDSP.
The change has no observeable behavior difference, its just code
juggling.

Git-Dch: Ignore
tags/debian/1.3_exp2
David Kalnischkies 5 years ago
parent
commit
d59671c9ee
6 changed files with 145 additions and 150 deletions
  1. +17
    -11
      apt-pkg/edsp/edspindexfile.cc
  2. +15
    -8
      apt-pkg/edsp/edspindexfile.h
  3. +27
    -39
      apt-pkg/edsp/edsplistparser.cc
  4. +14
    -9
      apt-pkg/edsp/edsplistparser.h
  5. +53
    -73
      apt-pkg/edsp/edspsystem.cc
  6. +19
    -10
      apt-pkg/edsp/edspsystem.h

+ 17
- 11
apt-pkg/edsp/edspindexfile.cc View File

@@ -21,37 +21,42 @@
#include <string>
/*}}}*/

// EDSP Index /*{{{*/
edspIndex::edspIndex(std::string const &File) : pkgDebianIndexRealFile(File, true), d(NULL)
// EDSP-like Index /*{{{*/
edspLikeIndex::edspLikeIndex(std::string const &File) : pkgDebianIndexRealFile(File, true)
{
}
std::string edspIndex::GetComponent() const
{
return "edsp";
}
std::string edspIndex::GetArchitecture() const
std::string edspLikeIndex::GetArchitecture() const
{
return std::string();
}
bool edspIndex::HasPackages() const
bool edspLikeIndex::HasPackages() const
{
return true;
}
bool edspIndex::Exists() const
bool edspLikeIndex::Exists() const
{
return true;
}
uint8_t edspIndex::GetIndexFlags() const
uint8_t edspLikeIndex::GetIndexFlags() const
{
return 0;
}
bool edspIndex::OpenListFile(FileFd &Pkg, std::string const &FileName)
bool edspLikeIndex::OpenListFile(FileFd &Pkg, std::string const &FileName)
{
if (FileName.empty() == false && FileName != "/nonexistent/stdin")
return pkgDebianIndexRealFile::OpenListFile(Pkg, FileName);
if (Pkg.OpenDescriptor(STDIN_FILENO, FileFd::ReadOnly) == false)
return _error->Error("Problem opening %s",FileName.c_str());
return true;
}
/*}}}*/
// EDSP Index /*{{{*/
edspIndex::edspIndex(std::string const &File) : edspLikeIndex(File)
{
}
std::string edspIndex::GetComponent() const
{
return "edsp";
}
pkgCacheListParser * edspIndex::CreateListParser(FileFd &Pkg)
{
@@ -84,4 +89,5 @@ const pkgIndexFile::Type *edspIndex::GetType() const
}
/*}}}*/

edspLikeIndex::~edspLikeIndex() {}
edspIndex::~edspIndex() {}

+ 15
- 8
apt-pkg/edsp/edspindexfile.h View File

@@ -18,23 +18,30 @@
class OpProgress;
class pkgCacheGenerator;

class APT_HIDDEN edspIndex : public pkgDebianIndexRealFile
class APT_HIDDEN edspLikeIndex : public pkgDebianIndexRealFile
{
/** \brief dpointer placeholder (for later in case we need it) */
void * const d;

protected:
APT_HIDDEN virtual pkgCacheListParser * CreateListParser(FileFd &Pkg) APT_OVERRIDE;
virtual bool OpenListFile(FileFd &Pkg, std::string const &File) APT_OVERRIDE;
virtual uint8_t GetIndexFlags() const APT_OVERRIDE;
virtual std::string GetComponent() const APT_OVERRIDE;
virtual std::string GetArchitecture() const APT_OVERRIDE;
public:

virtual const Type *GetType() const APT_OVERRIDE APT_CONST;
public:
virtual bool Exists() const APT_OVERRIDE;
virtual bool HasPackages() const APT_OVERRIDE;

edspLikeIndex(std::string const &File);
virtual ~edspLikeIndex();
};

class APT_HIDDEN edspIndex : public edspLikeIndex
{
protected:
APT_HIDDEN virtual pkgCacheListParser * CreateListParser(FileFd &Pkg) APT_OVERRIDE;
virtual std::string GetComponent() const APT_OVERRIDE;

public:
virtual const Type *GetType() const APT_OVERRIDE APT_CONST;

edspIndex(std::string const &File);
virtual ~edspIndex();
};


+ 27
- 39
apt-pkg/edsp/edsplistparser.cc View File

@@ -23,30 +23,22 @@

/*}}}*/

class edspListParserPrivate /*{{{*/
{
public:
FileFd extendedstates;
FileFd preferences;

edspListParserPrivate()
{
std::string const states = _config->FindFile("Dir::State::extended_states");
RemoveFile("edspListParserPrivate", states);
extendedstates.Open(states, FileFd::WriteOnly | FileFd::Create | FileFd::Exclusive, 0600);
std::string const prefs = _config->FindFile("Dir::Etc::preferences");
RemoveFile("edspListParserPrivate", prefs);
preferences.Open(prefs, FileFd::WriteOnly | FileFd::Create | FileFd::Exclusive, 0600);
}
};
/*}}}*/
// ListParser::edspListParser - Constructor /*{{{*/
edspListParser::edspListParser(FileFd *File) : debListParser(File), d(new edspListParserPrivate())
edspLikeListParser::edspLikeListParser(FileFd * const File) : debListParser(File)
{
}
edspListParser::edspListParser(FileFd * const File) : edspLikeListParser(File)
{
std::string const states = _config->FindFile("Dir::State::extended_states");
RemoveFile("edspListParserPrivate", states);
extendedstates.Open(states, FileFd::WriteOnly | FileFd::Create | FileFd::Exclusive, 0600);
std::string const prefs = _config->FindFile("Dir::Etc::preferences");
RemoveFile("edspListParserPrivate", prefs);
preferences.Open(prefs, FileFd::WriteOnly | FileFd::Create | FileFd::Exclusive, 0600);
}
/*}}}*/
// ListParser::NewVersion - Fill in the version structure /*{{{*/
bool edspListParser::NewVersion(pkgCache::VerIterator &Ver)
bool edspLikeListParser::NewVersion(pkgCache::VerIterator &Ver)
{
_system->SetVersionMapping(Ver->ID, Section.FindI("APT-ID", Ver->ID));
return debListParser::NewVersion(Ver);
@@ -55,19 +47,17 @@ bool edspListParser::NewVersion(pkgCache::VerIterator &Ver)
// ListParser::Description - Return the description string /*{{{*/
// ---------------------------------------------------------------------
/* Sorry, no description for the resolvers… */
std::vector<std::string> edspListParser::AvailableDescriptionLanguages()
std::vector<std::string> edspLikeListParser::AvailableDescriptionLanguages()
{
return {};
}
MD5SumValue edspListParser::Description_md5()
MD5SumValue edspLikeListParser::Description_md5()
{
return MD5SumValue("");
}
/*}}}*/
// ListParser::VersionHash - Compute a unique hash for this version /*{{{*/
// ---------------------------------------------------------------------
/* */
unsigned short edspListParser::VersionHash()
unsigned short edspLikeListParser::VersionHash()
{
if (Section.Exists("APT-Hash") == true)
return Section.FindI("APT-Hash");
@@ -76,6 +66,13 @@ unsigned short edspListParser::VersionHash()
return 0;
}
/*}}}*/
// ListParser::LoadReleaseInfo - Load the release information /*{{{*/
APT_CONST bool edspLikeListParser::LoadReleaseInfo(pkgCache::RlsFileIterator & /*FileI*/,
FileFd & /*File*/, std::string const &/*component*/)
{
return true;
}
/*}}}*/
// ListParser::ParseStatus - Parse the status field /*{{{*/
// ---------------------------------------------------------------------
/* The Status: line here is not a normal dpkg one but just one which tells
@@ -102,7 +99,7 @@ bool edspListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
{
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)
if (extendedstates.Write(out.c_str(), out.length()) == false)
return false;
}

@@ -111,7 +108,7 @@ bool edspListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
{
std::string out;
strprintf(out, "Package: %s\nPin: version %s\nPin-Priority: 9999\n\n", Pkg.FullName().c_str(), Ver.VerStr());
if (d->preferences.Write(out.c_str(), out.length()) == false)
if (preferences.Write(out.c_str(), out.length()) == false)
return false;
}

@@ -120,22 +117,13 @@ bool edspListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
{
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)
if (preferences.Write(out.c_str(), out.length()) == false)
return false;
}

return true;
}
/*}}}*/
// ListParser::LoadReleaseInfo - Load the release information /*{{{*/
APT_CONST bool edspListParser::LoadReleaseInfo(pkgCache::RlsFileIterator & /*FileI*/,
FileFd & /*File*/, std::string const &/*component*/)
{
return true;
}
/*}}}*/
edspListParser::~edspListParser() /*{{{*/
{
delete d;
}
/*}}}*/

edspLikeListParser::~edspLikeListParser() {}
edspListParser::~edspListParser() {}

+ 14
- 9
apt-pkg/edsp/edsplistparser.h View File

@@ -14,6 +14,7 @@
#include <apt-pkg/deblistparser.h>
#include <apt-pkg/md5.h>
#include <apt-pkg/pkgcache.h>
#include <apt-pkg/fileutl.h>

#include <string>

@@ -23,12 +24,8 @@
#include <apt-pkg/tagfile.h>
#endif

class FileFd;
class edspListParserPrivate;

class APT_HIDDEN edspListParser : public debListParser
class APT_HIDDEN edspLikeListParser : public debListParser
{
edspListParserPrivate * const d;
public:
virtual bool NewVersion(pkgCache::VerIterator &Ver) APT_OVERRIDE;
virtual std::vector<std::string> AvailableDescriptionLanguages() APT_OVERRIDE;
@@ -38,12 +35,20 @@ class APT_HIDDEN edspListParser : public debListParser
bool LoadReleaseInfo(pkgCache::RlsFileIterator &FileI,FileFd &File,
std::string const &section);

edspListParser(FileFd *File);
virtual ~edspListParser();
edspLikeListParser(FileFd *File);
virtual ~edspLikeListParser();
};

protected:
class APT_HIDDEN edspListParser : public edspLikeListParser
{
FileFd extendedstates;
FileFd preferences;

protected:
virtual bool ParseStatus(pkgCache::PkgIterator &Pkg,pkgCache::VerIterator &Ver) APT_OVERRIDE;

public:
edspListParser(FileFd *File);
virtual ~edspListParser();
};

#endif

+ 53
- 73
apt-pkg/edsp/edspsystem.cc View File

@@ -28,63 +28,22 @@

/*}}}*/

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;

RemoveFile("DeInitialize", tempStatesFile);
RemoveFile("DeInitialize", tempPrefsFile);
rmdir(tempDir.c_str());
}

~edspSystemPrivate() { DeInitialize(); }
};
// System::edspSystem - Constructor /*{{{*/
edspSystem::edspSystem() : pkgSystem("Debian APT solver interface", &debVS), d(new edspSystemPrivate()), StatusFile(NULL)
// System::System - Constructor /*{{{*/
edspLikeSystem::edspLikeSystem(char const * const Label) : pkgSystem(Label, &debVS)
{
}
/*}}}*/
// System::~debSystem - Destructor /*{{{*/
edspSystem::~edspSystem()
edspSystem::edspSystem() : edspLikeSystem("Debian APT solver interface")
{
delete StatusFile;
delete d;
}
/*}}}*/
// System::Lock - Get the lock /*{{{*/
bool edspSystem::Lock()
bool edspLikeSystem::Lock()
{
return true;
}
/*}}}*/
// System::UnLock - Drop a lock /*{{{*/
bool edspSystem::UnLock(bool /*NoErrors*/)
bool edspLikeSystem::UnLock(bool /*NoErrors*/)
{
return true;
}
@@ -93,68 +52,89 @@ bool edspSystem::UnLock(bool /*NoErrors*/)
// ---------------------------------------------------------------------
/* we can't use edsp input as input for real installations - just a
simulation can work, but everything else will fail bigtime */
pkgPackageManager *edspSystem::CreatePM(pkgDepCache * /*Cache*/) const
pkgPackageManager *edspLikeSystem::CreatePM(pkgDepCache * /*Cache*/) const
{
return NULL;
return nullptr;
}
/*}}}*/
// System::Initialize - Setup the configuration space.. /*{{{*/
bool edspSystem::Initialize(Configuration &Cnf)
bool edspLikeSystem::Initialize(Configuration &Cnf)
{
d->Initialize(Cnf);
Cnf.Set("Dir::Etc::preferencesparts", "/dev/null");
Cnf.Set("Dir::State::status","/dev/null");
Cnf.Set("Dir::State::lists","/dev/null");

Cnf.Set("Debug::NoLocking", "true");
Cnf.Set("APT::Get::Simulate", "true");

if (StatusFile) {
delete StatusFile;
StatusFile = 0;
}
StatusFile.reset(nullptr);
return true;
}
bool edspSystem::Initialize(Configuration &Cnf)
{
if (edspLikeSystem::Initialize(Cnf) == false)
return false;
std::string const tmp = GetTempDir();
char tmpname[300];
snprintf(tmpname, sizeof(tmpname), "%s/apt-edsp-solver-XXXXXX", tmp.c_str());
if (nullptr == mkdtemp(tmpname))
return false;
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);
return true;
}
/*}}}*/
// System::ArchiveSupported - Is a file format supported /*{{{*/
bool edspSystem::ArchiveSupported(const char * /*Type*/)
bool edspLikeSystem::ArchiveSupported(const char * /*Type*/)
{
return false;
}
/*}}}*/
// System::Score - Never use the EDSP system automatically /*{{{*/
signed edspSystem::Score(Configuration const &)
signed edspLikeSystem::Score(Configuration const &)
{
return -1000;
}
/*}}}*/
bool edspSystem::AddStatusFiles(std::vector<pkgIndexFile *> &List) /*{{{*/
{
if (StatusFile == 0)
{
if (_config->Find("edsp::scenario", "") == "/nonexistent/stdin")
StatusFile = new edspIndex("/nonexistent/stdin");
else
StatusFile = new edspIndex(_config->FindFile("edsp::scenario"));
}
List.push_back(StatusFile);
return true;
}
/*}}}*/
// System::FindIndex - Get an index file for status files /*{{{*/
bool edspSystem::FindIndex(pkgCache::PkgFileIterator File,
bool edspLikeSystem::FindIndex(pkgCache::PkgFileIterator File,
pkgIndexFile *&Found) const
{
if (StatusFile == 0)
return false;
if (StatusFile->FindInCache(*File.Cache()) == File)
{
Found = StatusFile;
Found = StatusFile.get();
return true;
}

return false;
}
/*}}}*/
bool edspSystem::AddStatusFiles(std::vector<pkgIndexFile *> &List) /*{{{*/
{
if (StatusFile == nullptr)
{
if (_config->Find("edsp::scenario", "") == "/nonexistent/stdin")
StatusFile.reset(new edspIndex("/nonexistent/stdin"));
else
StatusFile.reset(new edspIndex(_config->FindFile("edsp::scenario")));
}
List.push_back(StatusFile.get());
return true;
}
/*}}}*/

edspLikeSystem::~edspLikeSystem() {}
edspSystem::~edspSystem()
{
if (tempDir.empty())
return;

RemoveFile("~edspSystem", tempStatesFile);
RemoveFile("~edspSystem", tempPrefsFile);
rmdir(tempDir.c_str());
}

APT_HIDDEN edspSystem edspSys;

+ 19
- 10
apt-pkg/edsp/edspsystem.h View File

@@ -14,6 +14,7 @@
#include <apt-pkg/cacheiterators.h>
#include <apt-pkg/pkgcache.h>

#include <memory>
#include <vector>

#include <apt-pkg/macros.h>
@@ -22,28 +23,36 @@ class Configuration;
class pkgDepCache;
class pkgIndexFile;
class pkgPackageManager;
class edspIndex;

class edspSystemPrivate;
class APT_HIDDEN edspSystem : public pkgSystem
class APT_HIDDEN edspLikeSystem : public pkgSystem
{
/** \brief dpointer placeholder (for later in case we need it) */
edspSystemPrivate * const d;

edspIndex *StatusFile;

public:
protected:
std::unique_ptr<pkgIndexFile> StatusFile;

public:
virtual bool Lock() APT_OVERRIDE APT_CONST;
virtual bool UnLock(bool NoErrors = false) APT_OVERRIDE APT_CONST;
virtual pkgPackageManager *CreatePM(pkgDepCache *Cache) const APT_OVERRIDE APT_CONST;
virtual bool Initialize(Configuration &Cnf) APT_OVERRIDE;
virtual bool ArchiveSupported(const char *Type) APT_OVERRIDE APT_CONST;
virtual signed Score(Configuration const &Cnf) APT_OVERRIDE;
virtual bool AddStatusFiles(std::vector<pkgIndexFile *> &List) APT_OVERRIDE;
virtual bool FindIndex(pkgCache::PkgFileIterator File,
pkgIndexFile *&Found) const APT_OVERRIDE;

edspLikeSystem(char const * const Label);
virtual ~edspLikeSystem();
};

class APT_HIDDEN edspSystem : public edspLikeSystem
{
std::string tempDir;
std::string tempStatesFile;
std::string tempPrefsFile;

public:
virtual bool Initialize(Configuration &Cnf) APT_OVERRIDE;
virtual bool AddStatusFiles(std::vector<pkgIndexFile *> &List) APT_OVERRIDE;

edspSystem();
virtual ~edspSystem();
};


Loading…
Cancel
Save