Skip to content

Commit 64def78

Browse files
committed
inproved -1counter function
1 parent 6894bb2 commit 64def78

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

func/shared.func

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -730,29 +730,22 @@ is_type_valid() {
730730

731731
decrease_user_value() {
732732
USER="$1"
733-
key="$2"
734-
conf="$V_USERS/$USER/user.conf"
735-
736-
# Deleting $
737-
key=$(echo "${key//$/}")
733+
key="${2//$}"
738734

739735
# Parsing current value
740-
current_value=$(grep "$key=" $conf |cut -f 2 -d \')
741-
742-
# Checking result
743-
if [ -z "$current_value" ]; then
744-
echo "Error: Parsing error"
745-
log_event 'debug' "$E_PARSING $V_EVENT"
746-
exit $E_PARSING
736+
conf="$V_USERS/$USER/user.conf"
737+
old=$(grep "$key=" $conf | cut -f 2 -d \')
738+
if [ -z "$old" ]; then
739+
old=0
747740
fi
748741

749-
# Checking zero val
750-
if [ "$current_value" -gt 0 ]; then
751-
# Minus one
752-
new_value=$(expr $current_value - 1 )
753-
# Changing config
754-
sed -i "s/$key='$current_value'/$key='$new_value'/g" $conf
742+
# Decreasing
743+
if [ "$old" -le 1 ]; then
744+
new=0
745+
else
746+
new=$((old - 1 ))
755747
fi
748+
sed -i "s/$key='$old'/$key='$new'/g" $conf
756749
}
757750

758751

0 commit comments

Comments
 (0)