From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on sa.local.altlinux.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 From: Aleksei Nikiforov To: devel@lists.altlinux.org Date: Tue, 10 Dec 2019 18:23:37 +0300 Message-Id: <20191210152343.33867-33-darktemplar@altlinux.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191210152343.33867-1-darktemplar@altlinux.org> References: <20191210152343.33867-1-darktemplar@altlinux.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Cc: Aleksei Nikiforov Subject: [devel] [PATCH for apt 32/38] Add support for rpm's dbpath configuration X-BeenThere: devel@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: ALT Linux Team development discussions List-Id: ALT Linux Team development discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Dec 2019 15:25:51 -0000 X-List-Received-Date: Tue, 10 Dec 2019 15:25:51 -0000 Archived-At: List-Archive: List-Post: --- 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 &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 &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 &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 &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