[devel] [PATCH for apt 32/38] Add support for rpm's dbpath configuration
Aleksei Nikiforov
darktemplar на altlinux.org
Вт Дек 10 18:23:37 MSK 2019
---
apt/apt-pkg/rpm/rpmhandler.cc | 23 +++++++++++++++++++---
apt/apt-pkg/rpm/rpmpm.cc | 37 +++++++++++++++++++++++++++++++++++
apt/apt-pkg/rpm/rpmsystem.cc | 14 +++++++++++++
3 files changed, 71 insertions(+), 3 deletions(-)
diff --git a/apt/apt-pkg/rpm/rpmhandler.cc b/apt/apt-pkg/rpm/rpmhandler.cc
index 0bc6b4e..ed23cbe 100644
--- a/apt/apt-pkg/rpm/rpmhandler.cc
+++ b/apt/apt-pkg/rpm/rpmhandler.cc
@@ -384,6 +384,7 @@ RPMDBHandler::RPMDBHandler(bool WriteLock)
RpmIter = NULL;
#endif
string Dir = _config->Find("RPM::RootDir");
+ string DBDir = _config->Find("RPM::DBPath");
rpmReadConfigFiles(NULL, NULL);
ID = DataPath(false);
@@ -403,6 +404,17 @@ RPMDBHandler::RPMDBHandler(bool WriteLock)
Handler = rpmtsCreate();
rpmtsSetVSFlags(Handler, (rpmVSFlags_e)-1);
rpmtsSetRootDir(Handler, Dir.c_str());
+
+ if (!DBDir.empty())
+ {
+ std::string dbpath_macro = std::string("_dbpath ") + DBDir;
+ if (rpmDefineMacro(NULL, dbpath_macro.c_str(), 0) != 0)
+ {
+ _error->Error(_("Failed to set rpm dbpath"));
+ return;
+ }
+ }
+
if (rpmtsOpenDB(Handler, O_RDONLY) != 0)
{
_error->Error(_("could not open RPM database"));
@@ -412,6 +424,8 @@ RPMDBHandler::RPMDBHandler(bool WriteLock)
const char *RootDir = NULL;
if (!Dir.empty())
RootDir = Dir.c_str();
+ if (!DBDir.empty())
+ addMacro(NULL, "_dbpath", NULL, DBDir.c_str(), 0);
if (rpmdbOpen(RootDir, &Handler, O_RDONLY, 0644) != 0)
{
_error->Error(_("could not open RPM database"));
@@ -480,9 +494,12 @@ RPMDBHandler::~RPMDBHandler()
string RPMDBHandler::DataPath(bool DirectoryOnly)
{
string File = "Packages";
- char *tmp = (char *) rpmExpand("%{_dbpath}", NULL);
- string DBPath(_config->Find("RPM::RootDir")+tmp);
- free(tmp);
+ string DBPath = _config->Find("RPM::DBPath");
+ if (DBPath.empty()) {
+ char *tmp = (char *) rpmExpand("%{_dbpath}", NULL);
+ DBPath = _config->Find("RPM::RootDir") + tmp;
+ free(tmp);
+ }
if (DirectoryOnly == true)
return DBPath;
diff --git a/apt/apt-pkg/rpm/rpmpm.cc b/apt/apt-pkg/rpm/rpmpm.cc
index a6a3837..d2d3120 100644
--- a/apt/apt-pkg/rpm/rpmpm.cc
+++ b/apt/apt-pkg/rpm/rpmpm.cc
@@ -478,6 +478,14 @@ bool pkgRPMExtPM::ExecRPM(Item::RPMOps op, const std::vector<apt_item> &files)
Args[n++] = rootdir.c_str();
}
+ string DBDir = _config->Find("RPM::DBPath");
+ string DBDirArg;
+ if (!DBDir.empty())
+ {
+ DBDirArg = std::string("--dbpath=") + DBDir;
+ Args[n++] = DBDirArg.c_str();
+ }
+
Configuration::Item const *Opts;
if (op == Item::RPMErase)
{
@@ -835,6 +843,7 @@ bool pkgRPMLibPM::Process(const std::vector<apt_item> &install,
bool Success = false;
bool Interactive = _config->FindB("RPM::Interactive",true);
string Dir = _config->Find("RPM::RootDir");
+ string DBDir = _config->Find("RPM::DBPath");
int quiet = _config->FindI("quiet",0);
rpmReadConfigFiles(NULL, NULL);
@@ -855,6 +864,17 @@ bool pkgRPMLibPM::Process(const std::vector<apt_item> &install,
// 4.1 needs this always set even if NULL,
// otherwise all scriptlets fail
rpmtsSetRootDir(TS, Dir.c_str());
+
+ if (!DBDir.empty())
+ {
+ std::string dbpath_macro = std::string("_dbpath ") + DBDir;
+ if (rpmDefineMacro(NULL, dbpath_macro.c_str(), 0) != 0)
+ {
+ _error->Error(_("Failed to set rpm dbpath"));
+ goto exit;
+ }
+ }
+
if (rpmtsOpenDB(TS, O_RDWR) != 0)
{
_error->Error(_("Could not open RPM database"));
@@ -865,6 +885,8 @@ bool pkgRPMLibPM::Process(const std::vector<apt_item> &install,
const char *RootDir = NULL;
if (!Dir.empty())
RootDir = Dir.c_str();
+ if (!DBDir.empty())
+ addMacro(NULL, "_dbpath", NULL, DBDir.c_str(), 0);
if (rpmdbOpen(RootDir, &DB, O_RDWR|O_CREAT, 0644) != 0)
{
_error->Error(_("Could not open RPM database"));
@@ -1129,6 +1151,7 @@ bool pkgRPMLibPM::UpdateMarks()
}
std::string Dir = _config->Find("RPM::RootDir");
+ string DBDir = _config->Find("RPM::DBPath");
if (rpmReadConfigFiles(NULL, NULL) != 0)
{
@@ -1144,6 +1167,17 @@ bool pkgRPMLibPM::UpdateMarks()
// 4.1 needs this always set even if NULL,
// otherwise all scriptlets fail
rpmtsSetRootDir(TS, Dir.c_str());
+
+ if (!DBDir.empty())
+ {
+ std::string dbpath_macro = std::string("_dbpath ") + DBDir;
+ if (rpmDefineMacro(NULL, dbpath_macro.c_str(), 0) != 0)
+ {
+ _error->Error(_("Failed to set rpm dbpath"));
+ return false;
+ }
+ }
+
if (rpmtsOpenDB(TS, O_RDWR) != 0)
{
_error->Error(_("Could not open RPM database"));
@@ -1156,6 +1190,9 @@ bool pkgRPMLibPM::UpdateMarks()
RootDir = Dir.c_str();
}
+ if (!DBDir.empty())
+ addMacro(NULL, "_dbpath", NULL, DBDir.c_str(), 0);
+
if (rpmdbOpen(RootDir, &DB, O_RDWR|O_CREAT, 0644) != 0)
{
_error->Error(_("Could not open RPM database"));
diff --git a/apt/apt-pkg/rpm/rpmsystem.cc b/apt/apt-pkg/rpm/rpmsystem.cc
index e48267c..aba3297 100644
--- a/apt/apt-pkg/rpm/rpmsystem.cc
+++ b/apt/apt-pkg/rpm/rpmsystem.cc
@@ -275,6 +275,8 @@ string rpmSystem::DistroVer(Configuration const &Cnf)
string DistroVerPkg = _config->Find("Apt::DistroVerPkg");
string DistroVersion;
+ string DBDir = _config->Find("RPM::DBPath");
+
if (DistroVerPkg.empty())
return DistroVersion;
@@ -283,12 +285,24 @@ string rpmSystem::DistroVer(Configuration const &Cnf)
ts = rpmtsCreate();
rpmtsSetVSFlags(ts, (rpmVSFlags_e)-1);
rpmtsSetRootDir(ts, NULL);
+
+ if (!DBDir.empty())
+ {
+ std::string dbpath_macro = std::string("_dbpath ") + DBDir;
+ if (rpmDefineMacro(NULL, dbpath_macro.c_str(), 0) != 0)
+ {
+ return DistroVersion;
+ }
+ }
+
if (rpmtsOpenDB(ts, O_RDONLY))
return DistroVersion;
#else
rpmdb DB;
string RootDir = _config->Find("RPM::RootDir");
const char *RootDirStr = RootDir.empty() ? NULL : RootDir.c_str();
+ if (!DBDir.empty())
+ addMacro(NULL, "_dbpath", NULL, DBDir.c_str(), 0);
if (rpmdbOpen(RootDirStr, &DB, O_RDONLY, 0644))
return DistroVersion;
#endif
--
2.24.0
Подробная информация о списке рассылки Devel