Added return values on command errors
This commit is contained in:
parent
eb2a50ca95
commit
ecf937156e
9 changed files with 111 additions and 84 deletions
2
Makefile
2
Makefile
|
|
@ -41,7 +41,7 @@ test: $(BINDIR)/$(NAME)
|
||||||
clean:
|
clean:
|
||||||
rm $(ODIR)/*.o
|
rm $(ODIR)/*.o
|
||||||
|
|
||||||
clear: clean
|
clear:
|
||||||
rm $(BINDIR)/$(NAME)
|
rm $(BINDIR)/$(NAME)
|
||||||
|
|
||||||
install: $(BINDIR)/$(NAME)
|
install: $(BINDIR)/$(NAME)
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
sudo apt update >/dev/null 2>&1 || exit
|
sudo apt update >/dev/null || return $?
|
||||||
apt list --upgradable 2>/dev/null | tail -n +2 | awk -F "/" '{print $1" "$2}' | tr -d ']' | awk '{print $1" "$7" -> "$3}'
|
apt list --upgradable 2>/dev/null | tail -n +2 | awk -F "/" '{print $1" "$2}' | tr -d ']' | awk '{print $1" "$7" -> "$3}'
|
||||||
|
|
|
||||||
|
|
@ -2,5 +2,6 @@ CHECKUPDATES_DB="${TMPDIR:-/tmp}/checkup-db-${USER}/"
|
||||||
DBPath="$(pacman-conf DBPath)"
|
DBPath="$(pacman-conf DBPath)"
|
||||||
mkdir -p "$CHECKUPDATES_DB"
|
mkdir -p "$CHECKUPDATES_DB"
|
||||||
ln -sf "${DBPath}/local" "$CHECKUPDATES_DB" > /dev/null 2>&1
|
ln -sf "${DBPath}/local" "$CHECKUPDATES_DB" > /dev/null 2>&1
|
||||||
fakeroot pacman -Sy --dbpath "$CHECKUPDATES_DB" --logfile /dev/null >/dev/null 2>&1
|
fakeroot pacman -Sy --dbpath "$CHECKUPDATES_DB" --logfile /dev/null >/dev/null || return $?
|
||||||
pacman -Qu --dbpath "$CHECKUPDATES_DB/" 2> /dev/null | grep -v '\[.*\]'
|
pacman -Qu --dbpath "$CHECKUPDATES_DB/" 2> /dev/null | grep -v '\[.*\]'
|
||||||
|
return 0
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@
|
||||||
#define COMMANDS_H
|
#define COMMANDS_H
|
||||||
|
|
||||||
// pacman
|
// pacman
|
||||||
#define PACMAN_FETCH_COMMAND "CHECKUPDATES_DB=\"${TMPDIR:-/tmp}/checkup-db-${USER}/\"\nDBPath=\"$(pacman-conf DBPath)\"\nmkdir -p \"$CHECKUPDATES_DB\"\nln -sf \"${DBPath}/local\" \"$CHECKUPDATES_DB\" > /dev/null 2>&1\nfakeroot pacman -Sy --dbpath \"$CHECKUPDATES_DB\" --logfile /dev/null >/dev/null 2>&1\npacman -Qu --dbpath \"$CHECKUPDATES_DB/\" 2> /dev/null | grep -v '\\[.*\\]'"
|
#define PACMAN_FETCH_COMMAND "CHECKUPDATES_DB=\"${TMPDIR:-/tmp}/checkup-db-${USER}/\"\nDBPath=\"$(pacman-conf DBPath)\"\nmkdir -p \"$CHECKUPDATES_DB\"\nln -sf \"${DBPath}/local\" \"$CHECKUPDATES_DB\" > /dev/null 2>&1\nfakeroot pacman -Sy --dbpath \"$CHECKUPDATES_DB\" --logfile /dev/null >/dev/null || return $?\npacman -Qu --dbpath \"$CHECKUPDATES_DB/\" 2> /dev/null | grep -v '\\[.*\\]'\nreturn 0"
|
||||||
#define AUR_FETCH_COMMAND "yay -Qau 2>/dev/null"
|
#define AUR_FETCH_COMMAND "yay -Qau"
|
||||||
|
|
||||||
#define PACMAN_UPDATE_COMMAND "sudo pacman -Syu"
|
#define PACMAN_UPDATE_COMMAND "sudo pacman -Syu"
|
||||||
#define PACMAN_UPDATE_COMMAND_NOCONFIRM "sudo pacman -Syu --noconfirm"
|
#define PACMAN_UPDATE_COMMAND_NOCONFIRM "sudo pacman -Syu --noconfirm"
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
#define PACMAN_LOCAL_SIZE_CUT_COMMAND " |grep 'Installed Size'|cut -d':' -f2|tr -d ' '|cut -d'i' -f1 | tr -d 'B'|numfmt --from=iec|tr -d '\n'"
|
#define PACMAN_LOCAL_SIZE_CUT_COMMAND " |grep 'Installed Size'|cut -d':' -f2|tr -d ' '|cut -d'i' -f1 | tr -d 'B'|numfmt --from=iec|tr -d '\n'"
|
||||||
|
|
||||||
// apt/dpkg
|
// apt/dpkg
|
||||||
#define APT_FETCH_COMMAND "sudo apt update >/dev/null 2>&1 || exit\napt list --upgradable 2>/dev/null | tail -n +2 | awk -F \"/\" '{print $1\" \"$2}' | tr -d ']' | awk '{print $1\" \"$7\" -> \"$3}'"
|
#define APT_FETCH_COMMAND "sudo apt update >/dev/null || return $?\napt list --upgradable 2>/dev/null | tail -n +2 | awk -F \"/\" '{print $1\" \"$2}' | tr -d ']' | awk '{print $1\" \"$7\" -> \"$3}'"
|
||||||
#define APT_UPDATE_COMMAND "sudo apt upgrade"
|
#define APT_UPDATE_COMMAND "sudo apt upgrade"
|
||||||
#define APT_UPDATE_COMMAND_NOCONFIRM "echo y | sudo apt upgrade"
|
#define APT_UPDATE_COMMAND_NOCONFIRM "echo y | sudo apt upgrade"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@
|
||||||
#include "repos.hpp"
|
#include "repos.hpp"
|
||||||
|
|
||||||
//functions
|
//functions
|
||||||
void fetch_update(repo_update* r, const std::string& name, const std::string& command);
|
int fetch_update(repo_update* r, const std::string& name, const std::string& command);
|
||||||
|
|
||||||
void import_sizes(repo_update* ru, const char* ext_info_command, const char* loc_info_command, const char* ext_cut_command, const char* loc_cut_command);
|
int import_sizes(repo_update* ru, const char* ext_info_command, const char* loc_info_command, const char* ext_cut_command, const char* loc_cut_command);
|
||||||
|
|
||||||
#endif //FETCH_HPP
|
#endif //FETCH_HPP
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@ extern package_manager cur_pkgman;
|
||||||
// functions
|
// functions
|
||||||
bool exec_find(const std::string& name);
|
bool exec_find(const std::string& name);
|
||||||
|
|
||||||
void pacman_process(bool yay);
|
int pacman_process(bool yay);
|
||||||
|
|
||||||
void apt_process();
|
int apt_process();
|
||||||
|
|
||||||
#endif //PACKAGE_MAN_HPP
|
#endif //PACKAGE_MAN_HPP
|
||||||
|
|
|
||||||
|
|
@ -10,14 +10,17 @@
|
||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
|
|
||||||
//functions
|
//functions
|
||||||
void fetch_update(repo_update* r, const std::string& name, const std::string& command)
|
int fetch_update(repo_update* r, const std::string& name, const std::string& command)
|
||||||
{
|
{
|
||||||
r->packages.clear();
|
r->packages.clear();
|
||||||
r->name=name;
|
r->name=name;
|
||||||
r->name_max_length=0;
|
r->name_max_length=0;
|
||||||
r->vcur_max_length=0;
|
r->vcur_max_length=0;
|
||||||
r->vnew_max_length=0;
|
r->vnew_max_length=0;
|
||||||
std::string str=ztd::sh(command);
|
std::pair<std::string, int> cp = ztd::shp(command);
|
||||||
|
if(cp.second != 0)
|
||||||
|
return cp.second;
|
||||||
|
std::string str=cp.first;
|
||||||
|
|
||||||
unsigned long int i=0,j=0;
|
unsigned long int i=0,j=0;
|
||||||
while(i<str.size())
|
while(i<str.size())
|
||||||
|
|
@ -57,7 +60,7 @@ void fetch_update(repo_update* r, const std::string& name, const std::string& co
|
||||||
j=i;
|
j=i;
|
||||||
r->packages.push_back(pkg);
|
r->packages.push_back(pkg);
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -84,7 +87,7 @@ void get_loc_size(package_update* pkg, const char* info_command, const char* cut
|
||||||
pkg->current_install_size = 0;
|
pkg->current_install_size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void import_sizes(repo_update* ru, const char* ext_info_command, const char* loc_info_command, const char* ext_cut_command, const char* loc_cut_command)
|
int import_sizes(repo_update* ru, const char* ext_info_command, const char* loc_info_command, const char* ext_cut_command, const char* loc_cut_command)
|
||||||
{
|
{
|
||||||
const unsigned int n=ru->packages.size();
|
const unsigned int n=ru->packages.size();
|
||||||
#pragma omp parallel for
|
#pragma omp parallel for
|
||||||
|
|
@ -105,4 +108,5 @@ void import_sizes(repo_update* ru, const char* ext_info_command, const char* loc
|
||||||
ru->current_install_size += pkg.current_install_size;
|
ru->current_install_size += pkg.current_install_size;
|
||||||
}
|
}
|
||||||
ru->net_size = (long int) ru->new_install_size - (long int) ru->current_install_size;
|
ru->net_size = (long int) ru->new_install_size - (long int) ru->current_install_size;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
21
src/main.cpp
21
src/main.cpp
|
|
@ -5,11 +5,6 @@
|
||||||
#include "options.hpp"
|
#include "options.hpp"
|
||||||
#include "package_man.hpp"
|
#include "package_man.hpp"
|
||||||
|
|
||||||
long unsigned int new_download_size=0;
|
|
||||||
long unsigned int new_install_size=0;
|
|
||||||
long unsigned int current_install_size=0;
|
|
||||||
long int net_size=0;
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
//option process start
|
//option process start
|
||||||
|
|
@ -26,7 +21,7 @@ int main(int argc, char* argv[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !combine_target ) //no target -> all
|
if( !combine_target ) //no target -> all targets
|
||||||
{
|
{
|
||||||
opt_repo = true;
|
opt_repo = true;
|
||||||
opt_aur = true;
|
opt_aur = true;
|
||||||
|
|
@ -36,7 +31,7 @@ int main(int argc, char* argv[])
|
||||||
opt_pall = true;
|
opt_pall = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( opt_pall ) //all -> list + sizes
|
if ( opt_pall ) //pall -> list + sizes
|
||||||
{
|
{
|
||||||
opt_plist=true;
|
opt_plist=true;
|
||||||
opt_psizes=true;
|
opt_psizes=true;
|
||||||
|
|
@ -77,12 +72,12 @@ int main(int argc, char* argv[])
|
||||||
switch(cur_pkgman)
|
switch(cur_pkgman)
|
||||||
{
|
{
|
||||||
case pacman :
|
case pacman :
|
||||||
pacman_process(exec_find("yay")); break;
|
return pacman_process(exec_find("yay")); break;
|
||||||
case apt :
|
case apt :
|
||||||
apt_process(); break;
|
return apt_process(); break;
|
||||||
default : std::cerr << "Unsupported package manager\n"; break;
|
default :
|
||||||
|
std::cerr << "Unsupported package manager\n";
|
||||||
|
return 1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,12 +34,14 @@ void repo_print_process(repo_update& ru, ztd::color cl, bool print_size=true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void pacman_process(bool yay)
|
int pacman_process(bool yay)
|
||||||
{
|
{
|
||||||
|
int r=0, r2=0;
|
||||||
|
|
||||||
if(!exec_find("pacman"))
|
if(!exec_find("pacman"))
|
||||||
{
|
{
|
||||||
std::cerr << "pacman not found\n";
|
std::cerr << "pacman not found\n";
|
||||||
return;
|
return 1;
|
||||||
}
|
}
|
||||||
//fetch
|
//fetch
|
||||||
if(combine_fetch)
|
if(combine_fetch)
|
||||||
|
|
@ -49,14 +51,18 @@ void pacman_process(bool yay)
|
||||||
#pragma omp section
|
#pragma omp section
|
||||||
{
|
{
|
||||||
if(opt_repo)
|
if(opt_repo)
|
||||||
fetch_update(&repo, "REPO", PACMAN_FETCH_COMMAND);
|
r = fetch_update(&repo, "REPO", PACMAN_FETCH_COMMAND);
|
||||||
}
|
}
|
||||||
#pragma omp section
|
#pragma omp section
|
||||||
{
|
{
|
||||||
if(opt_aur && yay)
|
if(opt_aur && yay)
|
||||||
fetch_update(&aur, "AUR", AUR_FETCH_COMMAND);
|
r2 = fetch_update(&aur, "AUR", AUR_FETCH_COMMAND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(r!=0)
|
||||||
|
return r;
|
||||||
|
if(r2!=0)
|
||||||
|
return r2;
|
||||||
}
|
}
|
||||||
|
|
||||||
//process
|
//process
|
||||||
|
|
@ -65,8 +71,10 @@ void pacman_process(bool yay)
|
||||||
//size fetch
|
//size fetch
|
||||||
if( combine_size )
|
if( combine_size )
|
||||||
{
|
{
|
||||||
import_sizes(&repo, PACMAN_EXT_INFO_COMMAND, PACMAN_LOCAL_INFO_COMMAND, PACMAN_EXT_SIZE_CUT_COMMAND, PACMAN_LOCAL_SIZE_CUT_COMMAND);
|
r = import_sizes(&repo, PACMAN_EXT_INFO_COMMAND, PACMAN_LOCAL_INFO_COMMAND, PACMAN_EXT_SIZE_CUT_COMMAND, PACMAN_LOCAL_SIZE_CUT_COMMAND);
|
||||||
}
|
}
|
||||||
|
if(r!=0)
|
||||||
|
return r;
|
||||||
|
|
||||||
repo_print_process(repo, ztd::color::b_white);
|
repo_print_process(repo, ztd::color::b_white);
|
||||||
|
|
||||||
|
|
@ -79,9 +87,12 @@ void pacman_process(bool yay)
|
||||||
{
|
{
|
||||||
signal(SIGINT, SIG_IGN);
|
signal(SIGINT, SIG_IGN);
|
||||||
if(opt_noconfirm)
|
if(opt_noconfirm)
|
||||||
system(PACMAN_UPDATE_COMMAND_NOCONFIRM);
|
r = ztd::shr(PACMAN_UPDATE_COMMAND_NOCONFIRM);
|
||||||
else
|
else
|
||||||
system(PACMAN_UPDATE_COMMAND);
|
r = ztd::shr(PACMAN_UPDATE_COMMAND);
|
||||||
|
|
||||||
|
if(r!=0)
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -99,11 +110,15 @@ void pacman_process(bool yay)
|
||||||
{
|
{
|
||||||
signal(SIGINT, SIG_IGN);
|
signal(SIGINT, SIG_IGN);
|
||||||
if(opt_noconfirm)
|
if(opt_noconfirm)
|
||||||
system(AUR_UPDATE_COMMAND_NOCONFIRM);
|
r = ztd::shr(AUR_UPDATE_COMMAND_NOCONFIRM, true);
|
||||||
else
|
else
|
||||||
system(AUR_UPDATE_COMMAND);
|
r = ztd::shr(AUR_UPDATE_COMMAND, true);
|
||||||
|
|
||||||
|
if(r!=0)
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string apt_getrepo()
|
std::string apt_getrepo()
|
||||||
|
|
@ -120,31 +135,39 @@ std::string apt_getrepo()
|
||||||
return "UNKNOWN";
|
return "UNKNOWN";
|
||||||
}
|
}
|
||||||
|
|
||||||
void apt_process()
|
int apt_process()
|
||||||
{
|
{
|
||||||
|
int r=0;
|
||||||
|
|
||||||
if(!exec_find("apt"))
|
if(!exec_find("apt"))
|
||||||
{
|
{
|
||||||
std::cerr << "apt not found\n";
|
std::cerr << "apt not found\n";
|
||||||
return;
|
return 1;
|
||||||
}
|
}
|
||||||
if(!exec_find("apt-cache"))
|
if(!exec_find("apt-cache"))
|
||||||
{
|
{
|
||||||
std::cerr << "apt-cache not found\n";
|
std::cerr << "apt-cache not found\n";
|
||||||
return;
|
return 1;
|
||||||
}
|
}
|
||||||
if(!exec_find("dpkg"))
|
if(!exec_find("dpkg"))
|
||||||
{
|
{
|
||||||
std::cerr << "dpkg not found\n";
|
std::cerr << "dpkg not found\n";
|
||||||
return;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( combine_fetch )
|
if( combine_fetch )
|
||||||
{
|
{
|
||||||
fetch_update(&repo, apt_getrepo(), APT_FETCH_COMMAND);
|
r = fetch_update(&repo, apt_getrepo(), APT_FETCH_COMMAND);
|
||||||
}
|
}
|
||||||
|
if(r!=0)
|
||||||
|
return r;
|
||||||
|
|
||||||
if( combine_size )
|
if( combine_size )
|
||||||
{
|
{
|
||||||
import_sizes(&repo, APT_EXT_INFO_COMMAND, APT_LOCAL_INFO_COMMAND, APT_EXT_SIZE_CUT_COMMAND, APT_LOCAL_SIZE_CUT_COMMAND);
|
r = import_sizes(&repo, APT_EXT_INFO_COMMAND, APT_LOCAL_INFO_COMMAND, APT_EXT_SIZE_CUT_COMMAND, APT_LOCAL_SIZE_CUT_COMMAND);
|
||||||
}
|
}
|
||||||
|
if(r!=0)
|
||||||
|
return r;
|
||||||
|
|
||||||
repo_print_process(repo, ztd::color::b_white);
|
repo_print_process(repo, ztd::color::b_white);
|
||||||
|
|
||||||
|
|
@ -157,8 +180,12 @@ void apt_process()
|
||||||
{
|
{
|
||||||
signal(SIGINT, SIG_IGN);
|
signal(SIGINT, SIG_IGN);
|
||||||
if(opt_noconfirm)
|
if(opt_noconfirm)
|
||||||
system(APT_UPDATE_COMMAND_NOCONFIRM);
|
r = ztd::shr(APT_UPDATE_COMMAND_NOCONFIRM, true);
|
||||||
else
|
else
|
||||||
system(APT_UPDATE_COMMAND);
|
r = ztd::shr(APT_UPDATE_COMMAND, true);
|
||||||
|
|
||||||
|
if(r!=0)
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue