diff --git a/include/util.hpp b/include/util.hpp index d71051b..dd17950 100644 --- a/include/util.hpp +++ b/include/util.hpp @@ -46,7 +46,8 @@ bool taur_exec(std::vector 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> askUserForPkg(vector pkgs, TaurBackend& backend, bool useGit); diff --git a/src/main.cpp b/src/main.cpp index f3af25d..a2f9c3d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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; diff --git a/src/taur.cpp b/src/taur.cpp index 0416f39..4d156ba 100644 --- a/src/taur.cpp +++ b/src/taur.cpp @@ -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); @@ -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 _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", "--"}; diff --git a/src/util.cpp b/src/util.cpp index bed39b2..7c111db 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -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 cmd, string *output, bool exitOnFailure) { @@ -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.