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