Allow using `repo-add`/`repo-remove` from container in repo management actions
This commit is contained in:
parent
60a477af99
commit
bf67d1914d
|
@ -35,7 +35,14 @@ BuildActionMetaInfo::BuildActionMetaInfo()
|
||||||
.category = "Repo management",
|
.category = "Repo management",
|
||||||
.name = "Remove packages",
|
.name = "Remove packages",
|
||||||
.type = "remove-packages",
|
.type = "remove-packages",
|
||||||
.flags = {},
|
.flags = {
|
||||||
|
BuildActionFlagMetaInfo{
|
||||||
|
.id = static_cast<BuildActionFlagType>(PackageMovementFlags::UseContainer),
|
||||||
|
.name = "Use container",
|
||||||
|
.desc = "Uses `makecontainerpkg` to invoke `repo-remove`; eliminates the need to having pacman on the host by using docker/podman instead",
|
||||||
|
.param = "use-container",
|
||||||
|
},
|
||||||
|
},
|
||||||
.settings = {},
|
.settings = {},
|
||||||
.directory = true,
|
.directory = true,
|
||||||
.sourceDb = false,
|
.sourceDb = false,
|
||||||
|
@ -48,6 +55,12 @@ BuildActionMetaInfo::BuildActionMetaInfo()
|
||||||
.name = "Move packages",
|
.name = "Move packages",
|
||||||
.type = "move-packages",
|
.type = "move-packages",
|
||||||
.flags = {
|
.flags = {
|
||||||
|
BuildActionFlagMetaInfo{
|
||||||
|
.id = static_cast<BuildActionFlagType>(PackageMovementFlags::UseContainer),
|
||||||
|
.name = "Use container",
|
||||||
|
.desc = "Uses `makecontainerpkg` to invoke `repo-add`/`repo-remove`; eliminates the need to having pacman on the host by using docker/podman instead",
|
||||||
|
.param = "use-container",
|
||||||
|
},
|
||||||
BuildActionFlagMetaInfo{
|
BuildActionFlagMetaInfo{
|
||||||
.id = static_cast<BuildActionFlagType>(MovePackagesFlags::IgnoreExistingFiles),
|
.id = static_cast<BuildActionFlagType>(MovePackagesFlags::IgnoreExistingFiles),
|
||||||
.name = "Ignore existing files",
|
.name = "Ignore existing files",
|
||||||
|
|
|
@ -53,9 +53,17 @@ enum class BuildActionType : std::uint64_t {
|
||||||
|
|
||||||
using BuildActionFlagType = std::uint64_t;
|
using BuildActionFlagType = std::uint64_t;
|
||||||
constexpr BuildActionFlagType noBuildActionFlags = 0;
|
constexpr BuildActionFlagType noBuildActionFlags = 0;
|
||||||
|
enum class PackageMovementFlags : BuildActionFlagType {
|
||||||
|
None,
|
||||||
|
UseContainer = (1 << 0),
|
||||||
|
};
|
||||||
|
constexpr auto lastPackageMovementFlag = BuildActionFlagType(0);
|
||||||
|
enum class RemovePackagesFlags : BuildActionFlagType {
|
||||||
|
None,
|
||||||
|
};
|
||||||
enum class MovePackagesFlags : BuildActionFlagType {
|
enum class MovePackagesFlags : BuildActionFlagType {
|
||||||
None,
|
None,
|
||||||
IgnoreExistingFiles = (1 << 0),
|
IgnoreExistingFiles = (1 << (lastPackageMovementFlag + 1)),
|
||||||
};
|
};
|
||||||
enum class CheckForUpdatesFlags : BuildActionFlagType {
|
enum class CheckForUpdatesFlags : BuildActionFlagType {
|
||||||
None,
|
None,
|
||||||
|
@ -198,6 +206,7 @@ inline const BuildActionTypeMetaMapping &BuildActionMetaInfo::mappingForId(Build
|
||||||
|
|
||||||
} // namespace LibRepoMgr
|
} // namespace LibRepoMgr
|
||||||
|
|
||||||
|
CPP_UTILITIES_MARK_FLAG_ENUM_CLASS(LibRepoMgr, LibRepoMgr::PackageMovementFlags)
|
||||||
CPP_UTILITIES_MARK_FLAG_ENUM_CLASS(LibRepoMgr, LibRepoMgr::MovePackagesFlags)
|
CPP_UTILITIES_MARK_FLAG_ENUM_CLASS(LibRepoMgr, LibRepoMgr::MovePackagesFlags)
|
||||||
CPP_UTILITIES_MARK_FLAG_ENUM_CLASS(LibRepoMgr, LibRepoMgr::ReloadDatabaseFlags)
|
CPP_UTILITIES_MARK_FLAG_ENUM_CLASS(LibRepoMgr, LibRepoMgr::ReloadDatabaseFlags)
|
||||||
CPP_UTILITIES_MARK_FLAG_ENUM_CLASS(LibRepoMgr, LibRepoMgr::ReloadLibraryDependenciesFlags)
|
CPP_UTILITIES_MARK_FLAG_ENUM_CLASS(LibRepoMgr, LibRepoMgr::ReloadLibraryDependenciesFlags)
|
||||||
|
|
|
@ -341,6 +341,8 @@ protected:
|
||||||
std::vector<std::tuple<std::string_view, LibPkg::PackageLocation, bool>> m_packageLocations;
|
std::vector<std::tuple<std::string_view, LibPkg::PackageLocation, bool>> m_packageLocations;
|
||||||
boost::filesystem::path m_repoRemovePath;
|
boost::filesystem::path m_repoRemovePath;
|
||||||
boost::filesystem::path m_repoAddPath;
|
boost::filesystem::path m_repoAddPath;
|
||||||
|
boost::filesystem::path m_makeContainerPkgPath;
|
||||||
|
bool m_useContainer;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LIBREPOMGR_EXPORT RemovePackages : public PackageMovementAction {
|
struct LIBREPOMGR_EXPORT RemovePackages : public PackageMovementAction {
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <c++utilities/io/ansiescapecodes.h>
|
#include <c++utilities/io/ansiescapecodes.h>
|
||||||
#include <c++utilities/io/path.h>
|
#include <c++utilities/io/path.h>
|
||||||
|
|
||||||
|
#include <boost/process/env.hpp>
|
||||||
#include <boost/process/search_path.hpp>
|
#include <boost/process/search_path.hpp>
|
||||||
#include <boost/process/start_dir.hpp>
|
#include <boost/process/start_dir.hpp>
|
||||||
|
|
||||||
|
@ -33,26 +34,37 @@ PackageMovementAction::PackageMovementAction(ServiceSetup &setup, const std::sha
|
||||||
|
|
||||||
bool PackageMovementAction::prepareRepoAction(RequiredDatabases requiredDatabases)
|
bool PackageMovementAction::prepareRepoAction(RequiredDatabases requiredDatabases)
|
||||||
{
|
{
|
||||||
// initialize build action
|
// validate and read parameter/settings
|
||||||
auto configReadLock = init(BuildActionAccess::ReadConfig, requiredDatabases | RequiredDatabases::OneDestination, RequiredParameters::Packages);
|
auto configReadLock = init(BuildActionAccess::ReadConfig, requiredDatabases | RequiredDatabases::OneDestination, RequiredParameters::Packages);
|
||||||
if (std::holds_alternative<std::monostate>(configReadLock)) {
|
if (std::holds_alternative<std::monostate>(configReadLock)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
const auto flags = static_cast<PackageMovementFlags>(m_buildAction->flags);
|
||||||
|
m_useContainer = flags & PackageMovementFlags::UseContainer;
|
||||||
auto setupLock = m_setup.lockToRead();
|
auto setupLock = m_setup.lockToRead();
|
||||||
m_repoRemovePath = findExecutable(m_setup.building.repoRemovePath);
|
m_repoRemovePath = findExecutable(m_setup.building.repoRemovePath);
|
||||||
if (requiredDatabases & RequiredDatabases::OneSource) {
|
if (requiredDatabases & RequiredDatabases::OneSource) {
|
||||||
m_repoAddPath = findExecutable(m_setup.building.repoAddPath);
|
m_repoAddPath = findExecutable(m_setup.building.repoAddPath);
|
||||||
}
|
}
|
||||||
|
if (m_useContainer) {
|
||||||
|
m_makeContainerPkgPath = findExecutable(m_setup.building.makeContainerPkgPath);
|
||||||
|
}
|
||||||
|
|
||||||
// check executables
|
// check executables
|
||||||
if (!checkExecutable(m_repoRemovePath)) {
|
if (m_useContainer) {
|
||||||
reportError("Unable to find repo-remove executable \"" % m_setup.building.repoRemovePath + "\" in PATH.");
|
if (!checkExecutable(m_makeContainerPkgPath)) {
|
||||||
return false;
|
reportError("Unable to find makecontainerpkg executable \"" % m_setup.building.makeContainerPkgPath + "\" in PATH.");
|
||||||
}
|
return false;
|
||||||
if (requiredDatabases & RequiredDatabases::OneSource && !checkExecutable(m_repoAddPath)) {
|
}
|
||||||
reportError("Unable to find repo-add executable \"" % m_setup.building.repoAddPath + "\" in PATH.");
|
} else {
|
||||||
return false;
|
if (!checkExecutable(m_repoRemovePath)) {
|
||||||
|
reportError("Unable to find repo-remove executable \"" % m_setup.building.repoRemovePath + "\" in PATH.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (requiredDatabases & RequiredDatabases::OneSource && !checkExecutable(m_repoAddPath)) {
|
||||||
|
reportError("Unable to find repo-add executable \"" % m_setup.building.repoAddPath + "\" in PATH.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
setupLock.unlock();
|
setupLock.unlock();
|
||||||
|
|
||||||
|
@ -158,8 +170,14 @@ void RemovePackages::run()
|
||||||
repoRemoveProcess = m_buildAction->makeBuildProcess("repo-remove", m_workingDirectory + "/repo-remove.log",
|
repoRemoveProcess = m_buildAction->makeBuildProcess("repo-remove", m_workingDirectory + "/repo-remove.log",
|
||||||
std::bind(&RemovePackages::handleRepoRemoveResult, this, std::placeholders::_1, std::placeholders::_2))](UniqueLoggingLock &&lock) {
|
std::bind(&RemovePackages::handleRepoRemoveResult, this, std::placeholders::_1, std::placeholders::_2))](UniqueLoggingLock &&lock) {
|
||||||
repoRemoveProcess->locks().emplace_back(std::move(lock));
|
repoRemoveProcess->locks().emplace_back(std::move(lock));
|
||||||
repoRemoveProcess->launch(
|
if (m_useContainer) {
|
||||||
boost::process::start_dir(m_destinationRepoDirectory), m_repoRemovePath, m_destinationDatabaseFile, m_result.processedPackages);
|
repoRemoveProcess->launch(boost::process::start_dir(m_destinationRepoDirectory),
|
||||||
|
boost::process::env["PKGNAME"] = argsToString(m_buildAction->id), boost::process::env["TOOL"] = "repo-remove",
|
||||||
|
m_makeContainerPkgPath, "--", m_destinationDatabaseFile, m_result.processedPackages);
|
||||||
|
} else {
|
||||||
|
repoRemoveProcess->launch(
|
||||||
|
boost::process::start_dir(m_destinationRepoDirectory), m_repoRemovePath, m_destinationDatabaseFile, m_result.processedPackages);
|
||||||
|
}
|
||||||
buildAction->log()(Phrases::InfoMessage, "Invoking repo-remove within \"", m_destinationRepoDirectory, "\" for \"",
|
buildAction->log()(Phrases::InfoMessage, "Invoking repo-remove within \"", m_destinationRepoDirectory, "\" for \"",
|
||||||
m_destinationDatabaseFile, "\", see logfile for details\n");
|
m_destinationDatabaseFile, "\", see logfile for details\n");
|
||||||
});
|
});
|
||||||
|
@ -307,7 +325,13 @@ void MovePackages::run()
|
||||||
std::bind(&MovePackages::handleRepoAddResult, this, processSession, std::placeholders::_1, std::placeholders::_2))](
|
std::bind(&MovePackages::handleRepoAddResult, this, processSession, std::placeholders::_1, std::placeholders::_2))](
|
||||||
UniqueLoggingLock &&lock) {
|
UniqueLoggingLock &&lock) {
|
||||||
repoAddProcess->locks().emplace_back(std::move(lock));
|
repoAddProcess->locks().emplace_back(std::move(lock));
|
||||||
repoAddProcess->launch(boost::process::start_dir(m_destinationRepoDirectory), m_repoAddPath, m_destinationDatabaseFile, m_fileNames);
|
if (m_useContainer) {
|
||||||
|
repoAddProcess->launch(boost::process::start_dir(m_destinationRepoDirectory),
|
||||||
|
boost::process::env["PKGNAME"] = argsToString(m_buildAction->id), boost::process::env["TOOL"] = "repo-add",
|
||||||
|
m_makeContainerPkgPath, "--", m_destinationDatabaseFile, m_fileNames);
|
||||||
|
} else {
|
||||||
|
repoAddProcess->launch(boost::process::start_dir(m_destinationRepoDirectory), m_repoAddPath, m_destinationDatabaseFile, m_fileNames);
|
||||||
|
}
|
||||||
m_buildAction->log()(ps(Phrases::InfoMessage), "Invoking repo-add within \"", m_destinationRepoDirectory, "\" for \"",
|
m_buildAction->log()(ps(Phrases::InfoMessage), "Invoking repo-add within \"", m_destinationRepoDirectory, "\" for \"",
|
||||||
m_destinationDatabaseFile, "\", see logfile for details\n");
|
m_destinationDatabaseFile, "\", see logfile for details\n");
|
||||||
});
|
});
|
||||||
|
@ -319,8 +343,14 @@ void MovePackages::run()
|
||||||
std::bind(&MovePackages::handleRepoRemoveResult, this, processSession, std::placeholders::_1, std::placeholders::_2))](
|
std::bind(&MovePackages::handleRepoRemoveResult, this, processSession, std::placeholders::_1, std::placeholders::_2))](
|
||||||
UniqueLoggingLock &&lock) {
|
UniqueLoggingLock &&lock) {
|
||||||
repoRemoveProcess->locks().emplace_back(std::move(lock));
|
repoRemoveProcess->locks().emplace_back(std::move(lock));
|
||||||
repoRemoveProcess->launch(
|
if (m_useContainer) {
|
||||||
boost::process::start_dir(m_sourceRepoDirectory), m_repoRemovePath, m_sourceDatabaseFile, m_result.processedPackages);
|
repoRemoveProcess->launch(boost::process::start_dir(m_sourceRepoDirectory),
|
||||||
|
boost::process::env["PKGNAME"] = argsToString(m_buildAction->id), boost::process::env["TOOL"] = "repo-remove",
|
||||||
|
m_makeContainerPkgPath, "--", m_sourceDatabaseFile, m_result.processedPackages);
|
||||||
|
} else {
|
||||||
|
repoRemoveProcess->launch(
|
||||||
|
boost::process::start_dir(m_sourceRepoDirectory), m_repoRemovePath, m_sourceDatabaseFile, m_result.processedPackages);
|
||||||
|
}
|
||||||
m_buildAction->log()(ps(Phrases::InfoMessage), "Invoking repo-remove within \"", m_sourceRepoDirectory, "\" for \"", m_sourceDatabaseFile,
|
m_buildAction->log()(ps(Phrases::InfoMessage), "Invoking repo-remove within \"", m_sourceRepoDirectory, "\" for \"", m_sourceDatabaseFile,
|
||||||
"\", see logfile for details\n");
|
"\", see logfile for details\n");
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue