Skip to content

Commit

Permalink
Fixed a bug that prevented -Syu with no args from running + a crash w…
Browse files Browse the repository at this point in the history
…hen no packages were to be upgraded.

Also moved makepkg_list to util.cpp
  • Loading branch information
BurntRanch committed Apr 16, 2024
1 parent a76f1fc commit 232beff
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 33 deletions.
3 changes: 2 additions & 1 deletion include/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ bool taur_exec(std::vector<const char*> cmd, bool exitOnFailure = true);
void sanitizeStr(string& str);
bool is_package_from_syncdb(alpm_pkg_t *pkg, alpm_list_t *syncdbs);
bool commitTransactionAndRelease(bool soft = false);
void printPkgInfo(TaurPkg_t &pkg, string db_name, int index = -1);
void printPkgInfo(TaurPkg_t &pkg, string db_name, int index = -1);// faster than makepkg --packagelist
string makepkg_list(string pkg_name, string path);
void free_list_and_internals(alpm_list_t *list);
fmt::text_style getColorFromDBName(string db_name);
std::optional<std::vector<TaurPkg_t>> askUserForPkg(vector<TaurPkg_t> pkgs, TaurBackend& backend, bool useGit);
Expand Down
5 changes: 1 addition & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ bool execPacman(int argc, char* argv[]) {
return false;
}

int installPkg(alpm_list_t *pkgNames) {
if (!pkgNames)
return false;

int installPkg(alpm_list_t *pkgNames) {
bool useGit = config->useGit;
string cacheDir = config->cacheDir;

Expand Down
33 changes: 6 additions & 27 deletions src/taur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,32 +215,6 @@ bool TaurBackend::remove_pkg(alpm_list_t *pkgQueries, bool aurOnly) {
return true;
}

// faster than makepkg --packagelist
string makepkg_list(string pkg_name, string path) {
string ret;

string versionInfo = shell_exec("grep 'pkgver=' " + path + "/PKGBUILD | cut -d= -f2");
string pkgrel = shell_exec("grep 'pkgrel=' " + path + "/PKGBUILD | cut -d= -f2");
string epoch = shell_exec("grep 'epoch=' " + path + "/PKGBUILD | cut -d= -f2");

if (!pkgrel.empty() && pkgrel[0] != '\0')
versionInfo += '-' + pkgrel;

if (!epoch.empty() && epoch[0] != '\0')
versionInfo = epoch + ':' + versionInfo;

string arch = shell_exec("grep 'CARCH=' " + config->makepkgConf + " | cut -d= -f2 | sed -e \"s/'//g\" -e 's/\"//g'");
string arch_field = shell_exec("awk -F '[()]' '/^arch=/ {gsub(/\"/,\"\",$2); print $2}' " + path + "/PKGBUILD | sed -e \"s/'//g\" -e 's/\"//g'");

if (arch_field == "any")
arch = "any";

string pkgext = shell_exec("grep 'PKGEXT=' " + config->makepkgConf + " | cut -d= -f2 | sed -e \"s/'//g\" -e 's/\"//g'");

ret = path + "/" + pkg_name + '-' + versionInfo + '-' + arch + pkgext;
return ret;
}

bool TaurBackend::install_pkg(string pkg_name, string extracted_path, bool onlydownload) {
// never forget to sanitize
sanitizeStr(extracted_path);
Expand Down Expand Up @@ -481,8 +455,13 @@ bool TaurBackend::update_all_pkgs(string cacheDir, bool useGit) {
updatedPkgs++;
}

if (pkgs_to_install.size() <= 0) {
log_printf(LOG_ERROR, "No packages to be upgraded.\n");
return true;
}

// remove the last ' ' so we can pass it to pacman
pkgs_to_install.erase(pkgs_to_install.end()-1, pkgs_to_install.end());
pkgs_to_install.erase(pkgs_to_install.end()-1);
vector<string> _pkgs = split(pkgs_to_install, ' ');
log_printf(LOG_DEBUG, "running {} pacman -U --needed -- {}\n", config.sudo, pkgs_to_install);
cmd = {config.sudo.c_str(), "pacman", "-U", "--needed", "--"};
Expand Down
28 changes: 27 additions & 1 deletion src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ bool is_number(const string& s, bool allowSpace) {
if (allowSpace)
return !s.empty() && std::find_if(s.begin(), s.end(), [](unsigned char c) { return (!std::isdigit(c) && (c != ' ')); }) == s.end();
else
return !s.empty() && std::find_if(s.begin(), s.end(), [](unsigned char c) { return (!std::isdigit(c) && (c != ' ')); }) == s.end();
return !s.empty() && std::find_if(s.begin(), s.end(), [](unsigned char c) { return (!std::isdigit(c)); }) == s.end();
}

bool taur_read_exec(vector<const char*> cmd, string *output, bool exitOnFailure) {
Expand Down Expand Up @@ -327,6 +327,32 @@ void printPkgInfo(TaurPkg_t &pkg, string db_name, int index) {
fmt::println(" {}", pkg.desc);
}

// faster than makepkg --packagelist
string makepkg_list(string pkg_name, string path) {
string ret;

string versionInfo = shell_exec("grep 'pkgver=' " + path + "/PKGBUILD | cut -d= -f2");
string pkgrel = shell_exec("grep 'pkgrel=' " + path + "/PKGBUILD | cut -d= -f2");
string epoch = shell_exec("grep 'epoch=' " + path + "/PKGBUILD | cut -d= -f2");

if (!pkgrel.empty() && pkgrel[0] != '\0')
versionInfo += '-' + pkgrel;

if (!epoch.empty() && epoch[0] != '\0')
versionInfo = epoch + ':' + versionInfo;

string arch = shell_exec("grep 'CARCH=' " + config->makepkgConf + " | cut -d= -f2 | sed -e \"s/'//g\" -e 's/\"//g'");
string arch_field = shell_exec("awk -F '[()]' '/^arch=/ {gsub(/\"/,\"\",$2); print $2}' " + path + "/PKGBUILD | sed -e \"s/'//g\" -e 's/\"//g'");

if (arch_field == "any")
arch = "any";

string pkgext = shell_exec("grep 'PKGEXT=' " + config->makepkgConf + " | cut -d= -f2 | sed -e \"s/'//g\" -e 's/\"//g'");

ret = path + "/" + pkg_name + '-' + versionInfo + '-' + arch + pkgext;
return ret;
}

/** Ask the user to select a package out of a list.
* @param pkgs The list of packages, in a vector
* @param backend A reference to the TaurBackend responsible for fetching any AUR packages.
Expand Down

0 comments on commit 232beff

Please sign in to comment.