Skip to content

Commit

Permalink
sanitize config value + print sync's db name near the name
Browse files Browse the repository at this point in the history
  • Loading branch information
Toni500github committed Mar 11, 2024
1 parent 991af55 commit 49ae2f0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
7 changes: 7 additions & 0 deletions include/taur.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ struct TaurPkg_t {
string version;
string url;
vector<string> depends = vector<string>();
string db_name;
};

struct db_colors {
const string extra = BOLDMAGENTA;
const string multilib = BOLDCYAN;
const string core = BOLDYELLOW;
};

class TaurBackend {
Expand Down
6 changes: 3 additions & 3 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ void Config::loadConfigFile(string filename) {
exit(-1);
}

this->sudo = this->getConfigValue<string>("general.sudo", "sudo");
this->sudo = this->getConfigValue<string>("general.sudo", "sudo"); sanitizeStr(this->sudo);
this->useGit = this->getConfigValue<bool>("general.useGit", true);
this->aurOnly = this->getConfigValue<bool>("general.aurOnly", false);
this->makepkgBin = this->getConfigValue<string>("bins.makepkgBin", "makepkg");
this->cacheDir = this->getCacheDir();
this->makepkgBin = this->getConfigValue<string>("bins.makepkgBin", "makepkg"); sanitizeStr(this->makepkgBin);
this->cacheDir = this->getCacheDir(); sanitizeStr(this->cacheDir);
this->colors = this->getConfigValue<bool>("general.colors", true);
}
27 changes: 18 additions & 9 deletions src/taur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,17 +425,25 @@ vector<string> TaurBackend::getPkgFromJson(rapidjson::Document& doc, bool useGit

vector<TaurPkg_t> TaurBackend::search_pac(string query) {
sanitizeStr(query);
string cmd = "pacman -Qn | grep \"" + query + "\"";
// we search for the package name and print only the name, not the description
string cmd = "pacman -Ss \"" + query + "\" | awk '{if (NR % 2 != 0) print $0}'";
vector<string> pkgs_string = split(exec(cmd), '\n');

TaurPkg_t taur_pkg;
vector<TaurPkg_t> out;

for (size_t i = 0; i < pkgs_string.size(); i++) {
try {
vector<string> pkg = split(pkgs_string[i], ' ');
out.push_back((TaurPkg_t) { pkg[0], pkg[1], "" });
vector<string> pkg = split(pkgs_string[i], '/');
size_t space_pos = pkg[1].find(' ');
pkg[1].erase(space_pos);
taur_pkg.name = pkg[1];
taur_pkg.db_name = pkg[0];
std::cout << "pkg0: "<<pkg[0] << "pkg1: " << pkg[1] << std::endl ;
pkg = split(pkgs_string[i], ' ');
taur_pkg.version = pkg[1];
out.push_back(taur_pkg);
} catch (std::out_of_range e) {
log_printf(LOG_ERROR, _("Pacman did not return what we expected, Command: %s\n") + cmd);
log_printf(LOG_ERROR, _("Pacman did not return what we expected, Command: %s\n"), cmd.c_str());
exit(1);
}
}
Expand Down Expand Up @@ -482,14 +490,15 @@ std::optional<TaurPkg_t> TaurBackend::search(string query, bool useGit) {

for (int i = 0; i < aurPkgs.size(); i++)
std::cout
<< BOLDBLUE << "[" << i << "]: "
<< NOCOLOR << BOLD << "AUR/" << aurPkgs[i]
<< MAGENTA << i << " "
<< NOCOLOR << BOLDBLUE << "aur/" << BOLD << aurPkgs[i]
<< NOCOLOR <<
std::endl;
for (int i = 0; i < pacPkgs.size(); i++)
std::cout
<< BOLDCYAN << "[" << i + aurPkgs.size() << "]: "
<< NOCOLOR << BOLD << "SYNC/" << pacPkgs[i].name
<< MAGENTA << i + aurPkgs.size() << " "
<< BOLDMAGENTA << pacPkgs[i].db_name << '/' << BOLD << pacPkgs[i].name
<< " " << BOLDGREEN << pacPkgs[i].version
<< NOCOLOR <<
std::endl;

Expand Down

0 comments on commit 49ae2f0

Please sign in to comment.