Fix warnings
This commit is contained in:
parent
3d508f7c81
commit
fa969270c1
14
cli/main.cpp
14
cli/main.cpp
|
@ -15,7 +15,16 @@
|
|||
#include <c++utilities/io/inifile.h>
|
||||
#include <c++utilities/io/nativefilestream.h>
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#pragma GCC diagnostic ignored "-Wconversion"
|
||||
#pragma GCC diagnostic ignored "-Wshadow=compatible-local"
|
||||
#endif
|
||||
#include <tabulate/table.hpp>
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
|
@ -122,11 +131,12 @@ void configureColumnWidths(tabulate::Table &table)
|
|||
}
|
||||
auto totalAverageSize = 0.0;
|
||||
for (auto &column : columnStats) {
|
||||
totalAverageSize += (column.averageSize = static_cast<double>(column.totalSize) / column.rows);
|
||||
totalAverageSize += (column.averageSize = static_cast<double>(column.totalSize) / static_cast<double>(column.rows));
|
||||
}
|
||||
for (auto &column : columnStats) {
|
||||
column.averagePercentage = column.averageSize / totalAverageSize;
|
||||
column.width = std::max<std::size_t>(terminalSize.columns * column.averagePercentage, std::min<std::size_t>(column.maxSize, 10));
|
||||
column.width = std::max<std::size_t>(static_cast<std::size_t>(static_cast<double>(terminalSize.columns) * column.averagePercentage),
|
||||
std::min<std::size_t>(column.maxSize, 10u));
|
||||
}
|
||||
for (std::size_t columnIndex = 0; columnIndex != columnStats.size(); ++columnIndex) {
|
||||
table.column(columnIndex).format().width(columnStats[columnIndex].width);
|
||||
|
|
|
@ -94,17 +94,17 @@ bool Config::addDepsRecursivelyInTopoOrder(vector<unique_ptr<TopoSortItem>> &all
|
|||
const auto *const runtimeDependencies = &pkg->dependencies;
|
||||
const auto *const makeDependencies = addBuildDependencies ? &pkg->sourceInfo->makeDependencies : nullptr;
|
||||
const auto *const checkDependencies = addBuildDependencies ? &pkg->sourceInfo->checkDependencies : nullptr;
|
||||
for (const auto *dependencies : { runtimeDependencies, makeDependencies, checkDependencies }) {
|
||||
if (!dependencies) {
|
||||
for (const auto *dependenciesOfDependency : { runtimeDependencies, makeDependencies, checkDependencies }) {
|
||||
if (!dependenciesOfDependency) {
|
||||
continue;
|
||||
}
|
||||
for (const auto &dependency : *dependencies) {
|
||||
for (const auto &dependencyOfDependency : *dependenciesOfDependency) {
|
||||
// skip dependencies provided by the current package itself (FIXME: right now python 3.n depends on python<3.(n+1) which should be fixed)
|
||||
if (pkg->providesDependency(dependency)) {
|
||||
if (pkg->providesDependency(dependencyOfDependency)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!addDepsRecursivelyInTopoOrder(allItems, finishedItems, ignored, cycleTracking, dependency, options, true)) {
|
||||
if (!addDepsRecursivelyInTopoOrder(allItems, finishedItems, ignored, cycleTracking, dependencyOfDependency, options, true)) {
|
||||
// skip if a cycle has been detected
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -121,10 +121,10 @@ std::list<std::string> Config::forEachPackage(const std::function<std::string(Da
|
|||
Database *currentDb = &*dbIterator;
|
||||
++dbIterator;
|
||||
|
||||
const auto recordError = [&](auto &&error) {
|
||||
const auto recordError = [&](auto &&errorMessage) {
|
||||
lock_guard<mutex> lock(submitFailureMutex);
|
||||
cerr << Phrases::SubError << error << Phrases::End;
|
||||
errorMessages.emplace_back(error);
|
||||
cerr << Phrases::SubError << errorMessage << Phrases::End;
|
||||
errorMessages.emplace_back(errorMessage);
|
||||
};
|
||||
|
||||
const auto processPackages = [&] {
|
||||
|
@ -140,10 +140,10 @@ std::list<std::string> Config::forEachPackage(const std::function<std::string(Da
|
|||
break;
|
||||
} else if (dbIterator != dbEnd) {
|
||||
// process next database
|
||||
auto error = processNextDatabase(&*dbIterator);
|
||||
if (!error.empty()) {
|
||||
auto errorMessage = processNextDatabase(&*dbIterator);
|
||||
if (!errorMessage.empty()) {
|
||||
if (error != "skip") {
|
||||
recordError(move(error));
|
||||
recordError(std::move(errorMessage));
|
||||
}
|
||||
++dbIterator;
|
||||
continue;
|
||||
|
@ -161,11 +161,11 @@ std::list<std::string> Config::forEachPackage(const std::function<std::string(Da
|
|||
|
||||
// process next package
|
||||
try {
|
||||
auto error = processNextPackage(currentDb, currentPackage, dbMutex);
|
||||
if (!error.empty()) {
|
||||
recordError(move(error));
|
||||
auto errorMessage = processNextPackage(currentDb, currentPackage, dbMutex);
|
||||
if (!errorMessage.empty()) {
|
||||
recordError(std::move(errorMessage));
|
||||
}
|
||||
} catch (const runtime_error &e) {
|
||||
} catch (const std::runtime_error &e) {
|
||||
recordError(argsToString(currentPackage->name, ':', ' ', e.what()));
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -86,9 +86,9 @@ std::variant<std::vector<Database *>, std::string> Config::computeDatabaseDepend
|
|||
result.reserve(database.dependencies.size());
|
||||
auto error = addDatabaseDependencies(*this, database, result, visited, addSelf);
|
||||
if (!error.empty()) {
|
||||
return move(error);
|
||||
return std::variant<std::vector<Database *>, std::string>(std::move(error));
|
||||
}
|
||||
return move(result);
|
||||
return std::variant<std::vector<Database *>, std::string>(std::move(result));
|
||||
}
|
||||
|
||||
static void addDatabasesRequiringDatabase(
|
||||
|
|
|
@ -203,9 +203,9 @@ void Binary::load(const string &fileContent, const string &fileName)
|
|||
}
|
||||
}
|
||||
|
||||
static constexpr unsigned char toLower(const unsigned char c)
|
||||
static constexpr auto toLower(auto c)
|
||||
{
|
||||
return (c >= 'A' && c <= 'Z') ? (c + ('a' - 'A')) : c;
|
||||
return static_cast<decltype(c)>((c >= 'A' && c <= 'Z') ? (c + ('a' - 'A')) : c);
|
||||
}
|
||||
|
||||
static std::string toLower(std::string str)
|
||||
|
@ -349,35 +349,35 @@ void Binary::parseElf(BinaryReader &reader, const string *fileContent)
|
|||
// skip flags
|
||||
stream.seekg(4, ios_base::cur);
|
||||
// read sizes
|
||||
const std::uint16_t elfHeaderSize = readElfInt16(reader);
|
||||
const std::uint16_t programHeaderEntrySize = readElfInt16(reader);
|
||||
/*const std::uint16_t elfHeaderSize = */ readElfInt16(reader);
|
||||
/*const std::uint16_t programHeaderEntrySize = */ readElfInt16(reader);
|
||||
const std::uint16_t programHeaderEntryCount = readElfInt16(reader);
|
||||
const std::uint16_t sectionHeaderSize = readElfInt16(reader);
|
||||
/*const std::uint16_t sectionHeaderSize = */ readElfInt16(reader);
|
||||
const std::uint16_t sectionHeaderCount = readElfInt16(reader);
|
||||
const std::uint16_t nameTableIndex = readElfInt16(reader);
|
||||
/*const std::uint16_t nameTableIndex = */ readElfInt16(reader);
|
||||
|
||||
// read program header
|
||||
stream.seekg(static_cast<istream::off_type>(programHeaderOffset));
|
||||
virtualAddressMapping.reserve(2);
|
||||
for (std::uint16_t programHeaderIndex = 0; programHeaderIndex != programHeaderEntryCount; ++programHeaderIndex) {
|
||||
std::uint64_t fileOffset, virtualAddr, physicalAddr, fileSize, virtualSize, flags, align;
|
||||
std::uint64_t fileOffset, virtualAddr, /*physicalAddr,*/ fileSize, virtualSize /*, flags, align*/;
|
||||
const std::uint32_t type = readElfInt32(reader);
|
||||
if (binaryClass == BinaryClass::Class32Bit) {
|
||||
fileOffset = readElfInt32(reader);
|
||||
virtualAddr = readElfInt32(reader);
|
||||
physicalAddr = readElfInt32(reader);
|
||||
/*physicalAddr = */ readElfInt32(reader);
|
||||
fileSize = readElfInt32(reader);
|
||||
virtualSize = readElfInt32(reader);
|
||||
flags = readElfInt32(reader);
|
||||
align = readElfInt32(reader);
|
||||
/*flags = */ readElfInt32(reader);
|
||||
/*align = */ readElfInt32(reader);
|
||||
} else {
|
||||
flags = readElfInt32(reader);
|
||||
/*flags = */ readElfInt32(reader);
|
||||
fileOffset = readElfAddress(reader);
|
||||
virtualAddr = readElfAddress(reader);
|
||||
physicalAddr = readElfAddress(reader);
|
||||
/*physicalAddr = */ readElfAddress(reader);
|
||||
fileSize = readElfAddress(reader);
|
||||
virtualSize = readElfAddress(reader);
|
||||
align = readElfAddress(reader);
|
||||
/*align = */ readElfAddress(reader);
|
||||
}
|
||||
switch (type) {
|
||||
case ProgramHeaderTypes::Load:
|
||||
|
@ -387,26 +387,26 @@ void Binary::parseElf(BinaryReader &reader, const string *fileContent)
|
|||
}
|
||||
|
||||
// read section header
|
||||
std::uint64_t stringTableOffset = 0, stringTableSize = 0;
|
||||
/*std::uint64_t stringTableOffset = 0, stringTableSize = 0;*/
|
||||
stream.seekg(static_cast<istream::off_type>(sectionTableOffset));
|
||||
for (std::uint16_t sectionHeaderIndex = 0; sectionHeaderIndex != sectionHeaderCount; ++sectionHeaderIndex) {
|
||||
const std::uint32_t nameOffset = readElfInt32(reader);
|
||||
/*const std::uint32_t nameOffset = */ readElfInt32(reader);
|
||||
const std::uint32_t type = readElfInt32(reader);
|
||||
const std::uint64_t attributes = readElfAddress(reader);
|
||||
const std::uint64_t virtualMemoryAddress = readElfAddress(reader);
|
||||
/*const std::uint64_t attributes = */ readElfAddress(reader);
|
||||
/*const std::uint64_t virtualMemoryAddress = */ readElfAddress(reader);
|
||||
const std::uint64_t offset = readElfAddress(reader);
|
||||
const std::uint64_t size = readElfAddress(reader);
|
||||
const std::uint32_t indexInAssociatedSection = readElfInt32(reader);
|
||||
const std::uint32_t extraInfo = readElfInt32(reader);
|
||||
const std::uint64_t requiredAlignment = readElfAddress(reader);
|
||||
const std::uint64_t entrySize = readElfAddress(reader);
|
||||
/*const std::uint32_t indexInAssociatedSection = */ readElfInt32(reader);
|
||||
/*const std::uint32_t extraInfo = */ readElfInt32(reader);
|
||||
/*const std::uint64_t requiredAlignment = */ readElfAddress(reader);
|
||||
/*const std::uint64_t entrySize = */ readElfAddress(reader);
|
||||
const auto nextSectionHeaderOffset = stream.tellg();
|
||||
|
||||
// read section
|
||||
switch (type) {
|
||||
case BinarySectionTypes::StringTable: {
|
||||
stringTableOffset = offset;
|
||||
stringTableSize = size;
|
||||
/*stringTableOffset = offset;
|
||||
stringTableSize = size;*/
|
||||
break;
|
||||
}
|
||||
case BinarySectionTypes::DynamicLinkingInfo: {
|
||||
|
@ -541,29 +541,29 @@ void Binary::parsePe(BinaryReader &reader, iostream::off_type baseFileOffset)
|
|||
|
||||
// read rest of COFF header
|
||||
const auto numberOfSections = reader.readUInt16LE();
|
||||
const auto timeDateStamp = reader.readUInt32LE();
|
||||
const auto symbolTableOffset = reader.readUInt32LE();
|
||||
const auto symbolTableSize = reader.readUInt32LE();
|
||||
/*const auto timeDateStamp = */ reader.readUInt32LE();
|
||||
/*const auto symbolTableOffset = */ reader.readUInt32LE();
|
||||
/*const auto symbolTableSize = */ reader.readUInt32LE();
|
||||
const auto optionHeaderSize = reader.readUInt16LE();
|
||||
const auto characteristics = reader.readUInt16LE();
|
||||
/*const auto characteristics = */ reader.readUInt16LE();
|
||||
|
||||
// read PE optional header
|
||||
int64_t exportDirVirtualAddress = -1, exportDirSize = -1, importDirVirtualAddress = -1, importDirSize = -1;
|
||||
int64_t /*exportDirVirtualAddress = -1, exportDirSize = -1, */ importDirVirtualAddress = -1 /*, importDirSize = -1*/;
|
||||
if (optionHeaderSize) {
|
||||
const auto optionHeaderStart = static_cast<long>(stream.tellg());
|
||||
unsigned char minPeHeaderSize;
|
||||
uint64_t imageBase;
|
||||
/*uint64_t imageBase;*/
|
||||
switch (reader.readUInt16LE()) {
|
||||
case 0x020b:
|
||||
binaryClass = BinaryClass::Class64Bit;
|
||||
stream.seekg(optionHeaderStart + 24, ios_base::beg);
|
||||
imageBase = reader.readUInt64LE();
|
||||
/*imageBase = */ reader.readUInt64LE();
|
||||
minPeHeaderSize = 112;
|
||||
break;
|
||||
case 0x010b:
|
||||
binaryClass = BinaryClass::Class32Bit;
|
||||
stream.seekg(optionHeaderStart + 28, ios_base::beg);
|
||||
imageBase = reader.readUInt32LE();
|
||||
/*imageBase = */ reader.readUInt32LE();
|
||||
minPeHeaderSize = 96;
|
||||
break;
|
||||
// case 0x0107: ROM image, not relevant
|
||||
|
@ -579,22 +579,22 @@ void Binary::parsePe(BinaryReader &reader, iostream::off_type baseFileOffset)
|
|||
if (numberOfDirs < 16) {
|
||||
throw runtime_error("expected at least 16 directories in PE file");
|
||||
}
|
||||
exportDirVirtualAddress = reader.readUInt32LE();
|
||||
exportDirSize = reader.readUInt32LE();
|
||||
/*exportDirVirtualAddress = */ reader.readUInt32LE();
|
||||
/*exportDirSize = */ reader.readUInt32LE();
|
||||
importDirVirtualAddress = reader.readUInt32LE();
|
||||
importDirSize = reader.readUInt32LE();
|
||||
/*importDirSize = */ reader.readUInt32LE();
|
||||
// skip remaining dirs (not relevant here)
|
||||
stream.seekg(optionHeaderStart + optionHeaderSize, ios_base::beg);
|
||||
}
|
||||
|
||||
// read section table for mapping virtual addresses to file offsets
|
||||
PeSectionData importDataSection;
|
||||
std::int64_t dllNameOffset = -1, dllNameSize = -1;
|
||||
std::int64_t importLibraryDllNameOffset = -1, importLibraryDllNameSize = -1;
|
||||
for (auto sectionsLeft = numberOfSections; sectionsLeft; --sectionsLeft) {
|
||||
importDataSection.read(reader);
|
||||
if (!strncmp(importDataSection.name, ".idata$7", 8)) {
|
||||
dllNameOffset = importDataSection.fileOffset;
|
||||
dllNameSize = importDataSection.fileSize;
|
||||
importLibraryDllNameOffset = importDataSection.fileOffset;
|
||||
importLibraryDllNameSize = importDataSection.fileSize;
|
||||
}
|
||||
virtualAddressMapping.emplace_back(
|
||||
importDataSection.fileOffset, importDataSection.fileSize, importDataSection.virtualAddress, importDataSection.virtualSize);
|
||||
|
@ -629,9 +629,9 @@ void Binary::parsePe(BinaryReader &reader, iostream::off_type baseFileOffset)
|
|||
}
|
||||
|
||||
// read import library name
|
||||
if (dllNameOffset >= 0) {
|
||||
stream.seekg(baseFileOffset + dllNameOffset, ios_base::beg);
|
||||
name = reader.readTerminatedString(static_cast<size_t>(dllNameSize), 0);
|
||||
if (importLibraryDllNameOffset >= 0) {
|
||||
stream.seekg(baseFileOffset + importLibraryDllNameOffset, ios_base::beg);
|
||||
name = reader.readTerminatedString(static_cast<size_t>(importLibraryDllNameSize), 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -663,6 +663,7 @@ void Binary::parseAr(BinaryReader &reader)
|
|||
}
|
||||
|
||||
const auto fileOffset = reader.stream()->tellg();
|
||||
static_assert(std::is_scalar_v<std::decay_t<decltype(fileSizeStr)>>);
|
||||
const auto fileSize = stringToNumber<iostream::off_type>(fileSizeStr);
|
||||
const auto nextFileOffset = fileOffset + fileSize;
|
||||
if (endsWith(string_view(fileName), ".o")) {
|
||||
|
|
|
@ -19,9 +19,9 @@ namespace LibPkg {
|
|||
|
||||
static void moveLastValue(string &target, multimap<string, string> &multimap, const string &key)
|
||||
{
|
||||
const auto i = find_if(multimap.rbegin(), multimap.rend(), [&key](const pair<string, string> &i) { return i.first == key; });
|
||||
if (i != multimap.rend()) {
|
||||
target = move(i->second);
|
||||
const auto it = find_if(multimap.rbegin(), multimap.rend(), [&key](const pair<string, string> &i) { return i.first == key; });
|
||||
if (it != multimap.rend()) {
|
||||
target = move(it->second);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,8 +102,8 @@ void Config::loadPacmanConfig(const char *pacmanConfigPath)
|
|||
}
|
||||
}
|
||||
// add included mirrors
|
||||
for (auto range = scope.second.equal_range("Include"); range.first != range.second; ++range.first) {
|
||||
const auto &path = range.first->second;
|
||||
for (auto includeRange = scope.second.equal_range("Include"); includeRange.first != includeRange.second; ++includeRange.first) {
|
||||
const auto &path = includeRange.first->second;
|
||||
auto &includedIni = includedInis[path];
|
||||
if (includedIni.data().empty()) {
|
||||
try {
|
||||
|
@ -120,9 +120,9 @@ void Config::loadPacmanConfig(const char *pacmanConfigPath)
|
|||
if (!nestedScope.first.empty()) {
|
||||
continue;
|
||||
}
|
||||
for (auto range = nestedScope.second.equal_range("Server"); range.first != range.second; ++range.first) {
|
||||
for (auto serverRange = nestedScope.second.equal_range("Server"); serverRange.first != serverRange.second; ++serverRange.first) {
|
||||
for (const auto &arch : architectures) {
|
||||
string url = range.first->second;
|
||||
string url = serverRange.first->second;
|
||||
findAndReplace<string>(url, "$repo", db->name);
|
||||
findAndReplace<string>(url, "$arch", arch);
|
||||
db->mirrors.emplace_back(move(url));
|
||||
|
|
|
@ -984,8 +984,9 @@ PackageNameData PackageNameData::decompose(std::string_view packageName)
|
|||
if (!regex_match(packageName.cbegin(), packageName.cend(), match, packageNameRegex)) {
|
||||
return data;
|
||||
}
|
||||
static constexpr auto matchToStringView = [](auto match, std::size_t offset = 0) {
|
||||
return std::string_view(match.first + offset, static_cast<std::size_t>(match.length() - offset));
|
||||
static constexpr auto matchToStringView = [](auto regexMatch, std::size_t offset = 0) {
|
||||
return std::string_view(
|
||||
regexMatch.first + offset, static_cast<std::size_t>(regexMatch.length() - static_cast<std::cmatch::difference_type>(offset)));
|
||||
};
|
||||
data.targetPrefix = matchToStringView(match[2]);
|
||||
data.actualName = matchToStringView(match[3]);
|
||||
|
|
|
@ -73,11 +73,11 @@ void BuildProcessSession::DataForWebSession::writeFileData(
|
|||
const auto bytesLeftToRead = m_bytesToSendFromFile - bytesTransferred;
|
||||
boost::beast::net::async_write(session->socket(), boost::beast::http::make_chunk(boost::asio::buffer(*m_fileBuffer, bytesTransferred)),
|
||||
[this, &filePath, session, bytesLeftToRead, moreToRead = !eof && bytesLeftToRead](
|
||||
boost::system::error_code ec, std::size_t bytesTransferred) {
|
||||
boost::system::error_code ecWebClient, std::size_t bytesTransferredToWebClient) {
|
||||
// handle error
|
||||
CPP_UTILITIES_UNUSED(bytesTransferred)
|
||||
if (ec) {
|
||||
cerr << Phrases::WarningMessage << "Error sending \"" << filePath << "\" to client: " << ec.message() << Phrases::EndFlush;
|
||||
CPP_UTILITIES_UNUSED(bytesTransferredToWebClient)
|
||||
if (ecWebClient) {
|
||||
cerr << Phrases::WarningMessage << "Error sending \"" << filePath << "\" to client: " << ecWebClient.message() << Phrases::EndFlush;
|
||||
std::lock_guard<std::mutex> lock(m_session.m_mutex);
|
||||
clear();
|
||||
error = true;
|
||||
|
@ -226,10 +226,10 @@ void BuildProcessSession::writeNextBufferToLogFile(const boost::system::error_co
|
|||
if (m_logFileBuffers.outstandingBuffersToSend.empty()) {
|
||||
// close the logfile when the process exited and we've written all the output
|
||||
if (m_exited.load()) {
|
||||
boost::system::error_code error;
|
||||
m_logFile.close(error);
|
||||
if (error) {
|
||||
cerr << Phrases::WarningMessage << "Error closing \"" << m_logFilePath << "\": " << error.message() << Phrases::EndFlush;
|
||||
boost::system::error_code closeError;
|
||||
m_logFile.close(closeError);
|
||||
if (closeError) {
|
||||
cerr << Phrases::WarningMessage << "Error closing \"" << m_logFilePath << "\": " << closeError.message() << Phrases::EndFlush;
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
|
|
@ -50,7 +50,7 @@ enum class BuildActionType : std::uint64_t {
|
|||
};
|
||||
|
||||
using BuildActionFlagType = std::uint64_t;
|
||||
static constexpr BuildActionFlagType noBuildActionFlags = 0;
|
||||
constexpr BuildActionFlagType noBuildActionFlags = 0;
|
||||
enum class CheckForUpdatesFlags : BuildActionFlagType {
|
||||
None,
|
||||
ConsiderRegularPackage = (1 << 0), // be consistent with LibPkg::UpdateCheckOptions here
|
||||
|
|
|
@ -179,23 +179,23 @@ void PrepareBuild::run()
|
|||
auto existingPackages = m_setup.config.findPackages(packageName);
|
||||
auto foundSourcePackage = false;
|
||||
auto packageBuildData = PackageBuildData();
|
||||
for (auto &package : existingPackages) {
|
||||
for (auto &existingPackage : existingPackages) {
|
||||
// skip if package not relevant
|
||||
if (!isExistingPackageRelevant(packageName, package, packageBuildData, *destinationDb)) {
|
||||
if (!isExistingPackageRelevant(packageName, existingPackage, packageBuildData, *destinationDb)) {
|
||||
continue;
|
||||
}
|
||||
// skip if package has no source info
|
||||
const auto &sourceInfo = package.pkg->sourceInfo;
|
||||
const auto &sourceInfo = existingPackage.pkg->sourceInfo;
|
||||
if (!sourceInfo || sourceInfo->name.empty()) {
|
||||
continue;
|
||||
}
|
||||
//
|
||||
auto &buildData = m_buildDataByPackage[sourceInfo->name];
|
||||
buildData.specifiedIndex = currentIndex++;
|
||||
buildData.existingPackages.emplace_back(package.pkg);
|
||||
buildData.existingPackages.emplace_back(existingPackage.pkg);
|
||||
if (buildData.existingVersion.empty()
|
||||
|| LibPkg::PackageVersion::isNewer(LibPkg::PackageVersion::compare(package.pkg->version, buildData.existingVersion))) {
|
||||
buildData.existingVersion = package.pkg->version;
|
||||
|| LibPkg::PackageVersion::isNewer(LibPkg::PackageVersion::compare(existingPackage.pkg->version, buildData.existingVersion))) {
|
||||
buildData.existingVersion = existingPackage.pkg->version;
|
||||
}
|
||||
// assume we don't have sources if going to clean up the source directory
|
||||
// FIXME: It is a little bit inconsistent that in other places existing PackageBuildData is overridden and here it is re-used.
|
||||
|
@ -203,7 +203,7 @@ void PrepareBuild::run()
|
|||
buildData.hasSource = false;
|
||||
}
|
||||
foundSourcePackage = true;
|
||||
if (std::get<LibPkg::Database *>(package.db) == destinationDb) {
|
||||
if (std::get<LibPkg::Database *>(existingPackage.db) == destinationDb) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -670,16 +670,16 @@ void BatchItem::addNeededBatchItemsForPackage(LibPkg::Config &config, const std:
|
|||
// check other packages recursively
|
||||
auto foundPackage = false;
|
||||
const auto existingPackages = config.findPackages(dep);
|
||||
for (const auto &package : existingPackages) {
|
||||
for (const auto &existingPackage : existingPackages) {
|
||||
// skip if packge is not from any database available within that build
|
||||
const auto *const db = std::get<LibPkg::Database *>(package.db);
|
||||
const auto *const db = std::get<LibPkg::Database *>(existingPackage.db);
|
||||
if (requiredDbs.find(db->name) == requiredDbs.end()) {
|
||||
continue;
|
||||
}
|
||||
if (db->arch != destinationDb->arch) {
|
||||
continue;
|
||||
}
|
||||
addNeededBatchItemsForPackage(config, requiredDbs, destinationDb, batchItems, visitedPackages, *package.pkg);
|
||||
addNeededBatchItemsForPackage(config, requiredDbs, destinationDb, batchItems, visitedPackages, *existingPackage.pkg);
|
||||
foundPackage = true;
|
||||
}
|
||||
if (!foundPackage) {
|
||||
|
|
|
@ -80,14 +80,14 @@ void ReloadDatabase::run()
|
|||
auto packages = LibPkg::Package::fromDatabaseFile(move(dbFile));
|
||||
dbFileLock.lock().unlock();
|
||||
const auto configLock = m_setup.config.lockToWrite();
|
||||
auto *const db = m_setup.config.findDatabase(dbName, dbArch);
|
||||
if (!db) {
|
||||
auto *const destinationDb = m_setup.config.findDatabase(dbName, dbArch);
|
||||
if (!destinationDb) {
|
||||
m_buildAction->appendOutput(
|
||||
Phrases::ErrorMessage, "Loaded database file for \"", dbName, '@', dbArch, "\" but it no longer exists; discarding\n");
|
||||
session->addResponse(std::move(dbName));
|
||||
return;
|
||||
}
|
||||
db->replacePackages(packages, lastModified);
|
||||
destinationDb->replacePackages(packages, lastModified);
|
||||
} catch (const std::runtime_error &e) {
|
||||
m_buildAction->appendOutput(Phrases::ErrorMessage, "An error occurred when reloading database \"", dbName, '@', dbArch,
|
||||
"\" from local file \"", dbPath, "\": ", e.what(), '\n');
|
||||
|
|
|
@ -114,9 +114,9 @@ void ReloadLibraryDependencies::run()
|
|||
} else if (std::filesystem::exists(cachePath = cacheDir % arch % '/' + fileName, ec)) {
|
||||
path = std::move(cachePath);
|
||||
} else {
|
||||
for (const auto &cachePath : m_setup.config.packageCacheDirs) {
|
||||
std::error_code ec;
|
||||
if (std::filesystem::exists(path = cachePath % '/' + fileName, ec)) {
|
||||
for (const auto &possibleCachePath : m_setup.config.packageCacheDirs) {
|
||||
std::error_code ecFileExists;
|
||||
if (std::filesystem::exists(path = possibleCachePath % '/' + fileName, ecFileExists)) {
|
||||
break;
|
||||
}
|
||||
path.clear();
|
||||
|
@ -125,10 +125,10 @@ void ReloadLibraryDependencies::run()
|
|||
if (path.empty() && !db->mirrors.empty()) {
|
||||
const auto &mirror = db->mirrors.front(); // just use the first mirror for now
|
||||
if (startsWith(mirror, "file:")) {
|
||||
std::error_code ec;
|
||||
const auto canonPath
|
||||
= std::filesystem::canonical(argsToString(std::string_view(mirror.data() + 5, mirror.size() - 5), '/', fileName), ec);
|
||||
if (!ec) {
|
||||
std::error_code ecCanonical;
|
||||
const auto canonPath = std::filesystem::canonical(
|
||||
argsToString(std::string_view(mirror.data() + 5, mirror.size() - 5), '/', fileName), ecCanonical);
|
||||
if (!ecCanonical) {
|
||||
path = canonPath.string();
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -22,9 +22,9 @@ namespace Traits = CppUtilities::Traits;
|
|||
inline const char *getLastValue(const std::multimap<std::string, std::string> &multimap, const std::string &key)
|
||||
{
|
||||
using namespace std;
|
||||
const auto i = find_if(multimap.crbegin(), multimap.crend(), [&key](const pair<string, string> &i) { return i.first == key; });
|
||||
if (i != multimap.rend()) {
|
||||
return i->second.data();
|
||||
const auto it = find_if(multimap.crbegin(), multimap.crend(), [&key](const pair<string, string> &i) { return i.first == key; });
|
||||
if (it != multimap.rend()) {
|
||||
return it->second.data();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -32,9 +32,9 @@ inline const char *getLastValue(const std::multimap<std::string, std::string> &m
|
|||
inline std::optional<std::string_view> getLastValueSv(const std::multimap<std::string, std::string> &multimap, const std::string &key)
|
||||
{
|
||||
using namespace std;
|
||||
const auto i = find_if(multimap.crbegin(), multimap.crend(), [&key](const pair<string, string> &i) { return i.first == key; });
|
||||
if (i != multimap.rend()) {
|
||||
return i->second.data();
|
||||
const auto it = find_if(multimap.crbegin(), multimap.crend(), [&key](const pair<string, string> &i) { return i.first == key; });
|
||||
if (it != multimap.rend()) {
|
||||
return it->second.data();
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
|
|
@ -531,7 +531,7 @@ std::size_t ServiceSetup::restoreState()
|
|||
}
|
||||
}
|
||||
building.actions.resize(newActionsSize);
|
||||
for (std::size_t buildActionId = 0, size = building.actions.size(); buildActionId != size; ++buildActionId) {
|
||||
for (std::size_t buildActionId = 0u, buildActionsSize = building.actions.size(); buildActionId != buildActionsSize; ++buildActionId) {
|
||||
if (!building.actions[buildActionId]) {
|
||||
building.invalidActions.emplace(buildActionId);
|
||||
}
|
||||
|
|
|
@ -98,26 +98,26 @@ void getDatabases(const Params ¶ms, ResponseHandler &&handler)
|
|||
|
||||
void getUnresolved(const Params ¶ms, ResponseHandler &&handler)
|
||||
{
|
||||
const auto names(params.target.decodeValues("name"));
|
||||
const auto names = params.target.decodeValues("name");
|
||||
if (names.empty()) {
|
||||
throw BadRequest("parameter name missing");
|
||||
}
|
||||
|
||||
namespace JR = ReflectiveRapidJSON::JsonReflector;
|
||||
RAPIDJSON_NAMESPACE::Document document(RAPIDJSON_NAMESPACE::kObjectType);
|
||||
RAPIDJSON_NAMESPACE::Document::Object obj(document.GetObject());
|
||||
RAPIDJSON_NAMESPACE::Document::Object documentObj(document.GetObject());
|
||||
|
||||
auto lock = params.setup.config.lockToRead();
|
||||
const auto newPackages = [&] {
|
||||
const auto names(params.target.decodeValues("add"));
|
||||
vector<shared_ptr<Package>> newPackages;
|
||||
newPackages.reserve(names.size());
|
||||
for (const auto &name : names) {
|
||||
const auto newPackageNames = params.target.decodeValues("add");
|
||||
auto res = std::vector<std::shared_ptr<Package>>();
|
||||
res.reserve(newPackageNames.size());
|
||||
for (const auto &name : newPackageNames) {
|
||||
for (auto &package : params.setup.config.findPackages(name)) {
|
||||
newPackages.emplace_back(move(package.pkg));
|
||||
res.emplace_back(move(package.pkg));
|
||||
}
|
||||
}
|
||||
return newPackages;
|
||||
return res;
|
||||
}();
|
||||
const auto removedPackages = [&] {
|
||||
DependencySet removedProvides;
|
||||
|
@ -311,22 +311,22 @@ void getPackages(const Params ¶ms, ResponseHandler &&handler)
|
|||
auto log = LogContext();
|
||||
auto handleAurResponse
|
||||
= [handler{ std::move(handler) }, params{ std::move(params) }, document{ make_shared<RAPIDJSON_NAMESPACE::Document>(std::move(document)) },
|
||||
details](WebClient::AurQuerySession::ContainerType &&aurPackages) mutable {
|
||||
details](WebClient::AurQuerySession::ContainerType &&queriedAurPackages) mutable {
|
||||
std::vector<PackageSearchResult> aurPackageSearchResults;
|
||||
aurPackageSearchResults.reserve(aurPackages.size());
|
||||
auto lock = params.setup.config.lockToRead();
|
||||
auto array = document->GetArray();
|
||||
aurPackageSearchResults.reserve(queriedAurPackages.size());
|
||||
auto configLock = params.setup.config.lockToRead();
|
||||
auto documentArray = document->GetArray();
|
||||
if (details) {
|
||||
for (auto &package : aurPackages) {
|
||||
ReflectiveRapidJSON::JsonReflector::push(std::move(package), array, document->GetAllocator());
|
||||
for (auto &package : queriedAurPackages) {
|
||||
ReflectiveRapidJSON::JsonReflector::push(std::move(package), documentArray, document->GetAllocator());
|
||||
}
|
||||
} else if (!aurPackages.empty()) {
|
||||
for (auto &package : aurPackages) {
|
||||
} else if (!queriedAurPackages.empty()) {
|
||||
for (auto &package : queriedAurPackages) {
|
||||
ReflectiveRapidJSON::JsonReflector::push(
|
||||
PackageSearchResult{ params.setup.config.aur, std::move(package) }, array, document->GetAllocator());
|
||||
PackageSearchResult{ params.setup.config.aur, std::move(package) }, documentArray, document->GetAllocator());
|
||||
}
|
||||
}
|
||||
lock.unlock();
|
||||
configLock.unlock();
|
||||
handler(makeJson(params.request(), *document, params.target.hasPrettyFlag()));
|
||||
};
|
||||
if (mode == Mode::Name) {
|
||||
|
|
|
@ -41,14 +41,14 @@ void searchAurPackages(LogContext &log, ServiceSetup &setup, const std::string &
|
|||
std::shared_ptr<AurQuerySession> &multiSession)
|
||||
{
|
||||
auto session = std::make_shared<WebClient::SslSession>(ioContext, setup.webServer.sslContext,
|
||||
[&log, &setup, multiSession](WebClient::SslSession &session, const WebClient::HttpClientError &error) mutable {
|
||||
[&log, &setup, multiSession](WebClient::SslSession &session2, const WebClient::HttpClientError &error) mutable {
|
||||
if (error.errorCode != boost::beast::errc::success && error.errorCode != boost::asio::ssl::error::stream_truncated) {
|
||||
log(Phrases::ErrorMessage, "Failed to search AUR: ", error.what(), '\n');
|
||||
return;
|
||||
}
|
||||
|
||||
// parse retrieved JSON
|
||||
const auto &body = get<Response>(session.response).body();
|
||||
const auto &body = get<Response>(session2.response).body();
|
||||
try {
|
||||
const auto packages = Package::fromAurRpcJson(body.data(), body.size(), PackageOrigin::AurRpcSearch);
|
||||
|
||||
|
@ -89,38 +89,38 @@ std::shared_ptr<AurQuerySession> queryAurPackagesInternal(LogContext &log, Servi
|
|||
|
||||
for (auto i = packages.cbegin(), end = packages.cend(); i != end;) {
|
||||
auto session = make_shared<WebClient::SslSession>(ioContext, setup.webServer.sslContext,
|
||||
[&log, &setup, multiSession](WebClient::SslSession &session, const WebClient::HttpClientError &error) mutable {
|
||||
[&log, &setup, multiSession](WebClient::SslSession &session2, const WebClient::HttpClientError &error) mutable {
|
||||
if (error.errorCode != boost::beast::errc::success && error.errorCode != boost::asio::ssl::error::stream_truncated) {
|
||||
log(Phrases::ErrorMessage, "Failed to retrieve AUR packages from RPC: ", error.what(), '\n');
|
||||
return;
|
||||
}
|
||||
|
||||
// parse retrieved JSON
|
||||
const auto &body = get<Response>(session.response).body();
|
||||
const auto &body = get<Response>(session2.response).body();
|
||||
try {
|
||||
const auto packages = Package::fromAurRpcJson(body.data(), body.size());
|
||||
const auto packagesFromAur = Package::fromAurRpcJson(body.data(), body.size());
|
||||
|
||||
// cache the AUR packages
|
||||
auto lock = setup.config.lockToWrite();
|
||||
for (auto &package : packages) {
|
||||
for (auto &package : packagesFromAur) {
|
||||
setup.config.aur.updatePackage(package);
|
||||
}
|
||||
lock.unlock();
|
||||
|
||||
multiSession->addResponses(packages);
|
||||
multiSession->addResponses(packagesFromAur);
|
||||
} catch (const RAPIDJSON_NAMESPACE::ParseResult &e) {
|
||||
log(Phrases::ErrorMessage, "Unable to parse AUR package from RPC: ", serializeParseError(e), '\n');
|
||||
}
|
||||
});
|
||||
|
||||
const auto url = [&] {
|
||||
stringstream url;
|
||||
url << "/rpc/?v=5&type=info";
|
||||
stringstream urlSteam;
|
||||
urlSteam << "/rpc/?v=5&type=info";
|
||||
for (size_t batchIndex = 0; batchIndex != packagesPerQuery && i != end; ++batchIndex, ++i) {
|
||||
url << "&arg[]=";
|
||||
url << WebAPI::Url::encodeValue(packageNameFromIterator(i));
|
||||
urlSteam << "&arg[]=";
|
||||
urlSteam << WebAPI::Url::encodeValue(packageNameFromIterator(i));
|
||||
}
|
||||
return url.str();
|
||||
return urlSteam.str();
|
||||
}();
|
||||
|
||||
session->run(aurHost, aurPort, boost::beast::http::verb::get, url.data(), 11);
|
||||
|
@ -192,7 +192,7 @@ void queryAurSnapshots(LogContext &log, ServiceSetup &setup, const std::vector<A
|
|||
CPP_UTILITIES_UNUSED(log)
|
||||
for (const auto ¶ms : queryParams) {
|
||||
auto session = std::make_shared<WebClient::SslSession>(ioContext, setup.webServer.sslContext,
|
||||
[multiSession, params](WebClient::SslSession &session, const WebClient::HttpClientError &error) mutable {
|
||||
[multiSession, params](WebClient::SslSession &session2, const WebClient::HttpClientError &error) mutable {
|
||||
if (error.errorCode != boost::beast::errc::success && error.errorCode.message() != "stream truncated") {
|
||||
multiSession->addResponse(WebClient::AurSnapshotResult{ .packageName = *params.packageName,
|
||||
.error = "Unable to retrieve AUR snapshot tarball for package " % *params.packageName % ": " + error.what() });
|
||||
|
@ -200,7 +200,7 @@ void queryAurSnapshots(LogContext &log, ServiceSetup &setup, const std::vector<A
|
|||
}
|
||||
|
||||
// parse retrieved archive
|
||||
const auto &response = get<Response>(session.response);
|
||||
const auto &response = get<Response>(session2.response);
|
||||
if (response.result() != boost::beast::http::status::ok) {
|
||||
multiSession->addResponse(WebClient::AurSnapshotResult{ .packageName = *params.packageName,
|
||||
.error
|
||||
|
@ -212,9 +212,9 @@ void queryAurSnapshots(LogContext &log, ServiceSetup &setup, const std::vector<A
|
|||
auto snapshotFiles = FileMap{};
|
||||
try {
|
||||
snapshotFiles = extractFilesFromBuffer(body, *params.packageName, [](const char *, const char *, mode_t) { return true; });
|
||||
} catch (const runtime_error &error) {
|
||||
} catch (const std::runtime_error &extractionError) {
|
||||
multiSession->addResponse(WebClient::AurSnapshotResult{ .packageName = *params.packageName,
|
||||
.error = "Unable to extract AUR snapshot tarball for package " % *params.packageName % ": " + error.what() });
|
||||
.error = "Unable to extract AUR snapshot tarball for package " % *params.packageName % ": " + extractionError.what() });
|
||||
return;
|
||||
}
|
||||
auto result = AurSnapshotResult{ .packageName = *params.packageName };
|
||||
|
@ -243,9 +243,9 @@ void queryAurSnapshots(LogContext &log, ServiceSetup &setup, const std::vector<A
|
|||
const auto targetDir = *params.targetDirectory % '/' + directoryPath;
|
||||
try {
|
||||
filesystem::create_directories(targetDir);
|
||||
} catch (const filesystem::filesystem_error &error) {
|
||||
} catch (const filesystem::filesystem_error &fileSystemError) {
|
||||
multiSession->addResponse(WebClient::AurSnapshotResult{
|
||||
.packageName = *params.packageName, .error = "Unable to make directory " % targetDir % ": " + error.what() });
|
||||
.packageName = *params.packageName, .error = "Unable to make directory " % targetDir % ": " + fileSystemError.what() });
|
||||
return;
|
||||
}
|
||||
for (const auto &file : directory.second) {
|
||||
|
@ -254,9 +254,9 @@ void queryAurSnapshots(LogContext &log, ServiceSetup &setup, const std::vector<A
|
|||
if (file.type == ArchiveFileType::Link) {
|
||||
try {
|
||||
filesystem::create_symlink(file.content, targetPath);
|
||||
} catch (const filesystem::filesystem_error &error) {
|
||||
multiSession->addResponse(WebClient::AurSnapshotResult{
|
||||
.packageName = *params.packageName, .error = "Unable to make symlink " % targetPath % ": " + error.what() });
|
||||
} catch (const filesystem::filesystem_error &fileSystemError) {
|
||||
multiSession->addResponse(WebClient::AurSnapshotResult{ .packageName = *params.packageName,
|
||||
.error = "Unable to make symlink " % targetPath % ": " + fileSystemError.what() });
|
||||
return;
|
||||
}
|
||||
continue;
|
||||
|
|
|
@ -118,7 +118,8 @@ void Session::received(boost::beast::error_code ec, std::size_t bytesTransferred
|
|||
void SslSession::run(const char *host, const char *port, http::verb verb, const char *target, unsigned int version)
|
||||
{
|
||||
// set SNI Hostname (many hosts need this to handshake successfully)
|
||||
if (!SSL_set_tlsext_host_name(m_stream.native_handle(), const_cast<char *>(host))) {
|
||||
if (!SSL_ctrl(
|
||||
m_stream.native_handle(), SSL_CTRL_SET_TLSEXT_HOSTNAME, TLSEXT_NAMETYPE_host_name, reinterpret_cast<void *>(const_cast<char *>(host)))) {
|
||||
m_handler(*this,
|
||||
HttpClientError(
|
||||
"setting SNI hostname", boost::beast::error_code{ static_cast<int>(::ERR_get_error()), boost::asio::error::get_ssl_category() }));
|
||||
|
@ -233,17 +234,17 @@ std::variant<string, std::shared_ptr<Session>, std::shared_ptr<SslSession>> runS
|
|||
const std::string &target, std::function<void(SessionData, const HttpClientError &)> &&handler, std::string &&destinationPath,
|
||||
std::string_view userName, std::string_view password, ArgType &&...args)
|
||||
{
|
||||
auto session = make_shared<SessionType>(args..., [handler{ move(handler) }](auto &session, const HttpClientError &error) mutable {
|
||||
handler(SessionData{ session.shared_from_this(), session.request, session.response, session.destinationFilePath }, error);
|
||||
auto session = make_shared<SessionType>(args..., [handler{ move(handler) }](auto &session2, const HttpClientError &error) mutable {
|
||||
handler(SessionData{ session2.shared_from_this(), session2.request, session2.response, session2.destinationFilePath }, error);
|
||||
});
|
||||
if (!userName.empty()) {
|
||||
const auto authInfo = userName % ":" + password;
|
||||
session->request.set(boost::beast::http::field::authorization,
|
||||
"Basic " + encodeBase64(reinterpret_cast<const std::uint8_t *>(authInfo.data()), authInfo.size()));
|
||||
"Basic " + encodeBase64(reinterpret_cast<const std::uint8_t *>(authInfo.data()), static_cast<std::uint32_t>(authInfo.size())));
|
||||
}
|
||||
session->destinationFilePath = move(destinationPath);
|
||||
session->run(host.data(), port.data(), http::verb::get, target.data());
|
||||
return move(session);
|
||||
return std::variant<string, std::shared_ptr<Session>, std::shared_ptr<SslSession>>(std::move(session));
|
||||
}
|
||||
|
||||
std::variant<string, std::shared_ptr<Session>, std::shared_ptr<SslSession>> runSessionFromUrl(boost::asio::io_context &ioContext,
|
||||
|
|
Loading…
Reference in New Issue