mirror of
https://github.com/scorpion-26/gBar.git
synced 2024-11-21 18:52:49 +00:00
Fix off by one error in default update script
This commit is contained in:
parent
1c6cd3bd2b
commit
259083a904
4 changed files with 30 additions and 7 deletions
|
@ -54,8 +54,9 @@ AudioScrollSpeed: 5
|
|||
|
||||
# Command that is run to check if there are out-of-date packages.
|
||||
# The script should return *ONLY* a number. If it doesn't output a number, updates are no longer checked.
|
||||
# Default value is applicable for Arch Linux. (See src/Config.h for explanation on the default command)
|
||||
CheckPackagesCommand: pac="$(checkupdates)"; if [ $? -eq 127 ] ; then exit 127; fi; echo -n "$pac" | wc -l
|
||||
# Default value is applicable for Arch Linux. (See data/update.sh for a human-readable version)
|
||||
CheckPackagesCommand: p="$(checkupdates)"; e=$?; if [ $e -eq 127 ] ; then exit 127; fi; if [ $e -eq 2 ] ; then echo "0" && exit 0; fi; echo "$p" | wc -l
|
||||
|
||||
|
||||
# How often to check for updates. In seconds
|
||||
CheckUpdateInterval: 300
|
||||
|
|
23
data/update.sh
Executable file
23
data/update.sh
Executable file
|
@ -0,0 +1,23 @@
|
|||
#/bin/sh
|
||||
|
||||
# This script is not used by default. It is a human-readable version of the default Arch-applicable
|
||||
# package command with explanations
|
||||
|
||||
updates="$(checkupdates)";
|
||||
exitCode=$?;
|
||||
|
||||
if [ $exitCode -eq 127 ] ; then
|
||||
# checkupdates wasn't found.
|
||||
# Forward the error to gBar, so gBar can shut down the widget
|
||||
# This is done, so we don't bother non-Arch systems with update checking
|
||||
exit 127;
|
||||
fi
|
||||
|
||||
if [ $exitCode -eq 2 ] ; then
|
||||
# Zero packages out-of-date. We need to handle this case, since 'echo "$updates" | wc -l' would return 1
|
||||
echo "0" && exit 0
|
||||
fi
|
||||
|
||||
# We need the extra newline (-n option omitted), since 'echo -n $"updates" | wc -l' is off by one,
|
||||
# since 'echo -n $"updates"' has a \0 at the end
|
||||
echo "$updates" | wc -l
|
|
@ -17,9 +17,8 @@ public:
|
|||
std::string defaultWorkspaceSymbol = "";
|
||||
|
||||
// Script that returns how many packages are out-of-date. The script should only print a number!
|
||||
// The default script runs checkupdates, and forcefully exits when checkupdates is not found, so gBar can disable the package widget.
|
||||
// "checkupdates | wc -l" would always return 0 on stdout, which gBar accepts
|
||||
std::string checkPackagesCommand = "pac=\"$(checkupdates)\"; if [ $? -eq 127 ] ; then exit 127; fi; echo -n \"$pac\" | wc -l";
|
||||
// See data/update.sh for a human-readable version
|
||||
std::string checkPackagesCommand = "p=\"$(checkupdates)\"; e=$?; if [ $e -eq 127 ] ; then exit 127; fi; if [ $e -eq 2 ] ; then echo \"0\" && exit 0; fi; echo \"$p\" | wc -l";
|
||||
|
||||
bool centerTime = true;
|
||||
bool audioRevealer = false;
|
||||
|
|
|
@ -563,10 +563,10 @@ namespace System
|
|||
ASSERT(feof(pipe), "GetOutdatedPackages: Cannot read to eof!");
|
||||
|
||||
int exitCode = pclose(pipe) / 256;
|
||||
if (exitCode == 127)
|
||||
if (exitCode != 0)
|
||||
{
|
||||
configMutex.lock();
|
||||
// Invalid script
|
||||
// Invalid script/error
|
||||
LOG("GetOutdatedPackages: Invalid command. Disabling package widget!");
|
||||
RuntimeConfig::Get().hasPackagesScript = false;
|
||||
configMutex.unlock();
|
||||
|
|
Loading…
Reference in a new issue