# HG changeset patch # User Christophe Lincoln # Date 1487691556 -3600 # Node ID 2499947037cfa120f1d6713a4d88f73c8135e434 # Parent 1d0317d8d6891f1eefcc9c9453c7e2965be0ef15 Bettercount of messages and del file + debug empty messages diff -r 1d0317d8d689 -r 2499947037cf web/bugs.cgi --- a/web/bugs.cgi Tue Feb 21 14:36:17 2017 +0100 +++ b/web/bugs.cgi Tue Feb 21 16:39:16 2017 +0100 @@ -359,7 +359,7 @@ # Write a new message new_msg() { date=$(date "+%Y-%m-%d %H:%M") - msgs=$(ls -1 $bugdir/$id/msg.* | wc -l) + msgs=$(ls -1 $bugdir/$id/msg.* | cut -d "." -f 2 | sort -n | tail -n 1) count=$(($msgs + 1)) if check_auth; then USER="$user" @@ -726,15 +726,13 @@ js_redirection_to "$script?id=$id" fi ;; *\ id\ *) - # Empty deleted messages to keep msg count working. header html_header id="$(GET id)" [ "$(GET close)" ] && close_bug [ "$(GET open)" ] && open_bug [ "$(GET msg)" ] && new_msg - [ "$(GET delmsg)" ] && rm -f $bugdir/$id/msg.$(GET delmsg) && \ - touch $bugdir/$id/msg.$(GET delmsg) + [ "$(GET delmsg)" ] && rm -f $bugdir/$id/msg.$(GET delmsg) msgs=$(fgrep MSG= $bugdir/$id/msg.* | wc -l) user_box . $bugdir/$id/bug.conf diff -r 1d0317d8d689 -r 2499947037cf web/plugins/debug/debug.cgi --- a/web/plugins/debug/debug.cgi Tue Feb 21 14:36:17 2017 +0100 +++ b/web/plugins/debug/debug.cgi Tue Feb 21 16:39:16 2017 +0100 @@ -9,14 +9,16 @@ html_header user_box if check_auth && ! admin_user; then - gettext "You must be admin to debug" - exit 0 + echo "You must be admin to debug" && exit 0 fi cat << EOT
Dashboard

Debug interface

+

+ Check for corrupted config files and empty messages. +

EOT # Handle ?debug&del request if [ "$(GET del)" ]; then @@ -34,13 +36,64 @@ do if [ $(cat ${bugdir}/${id}/bug.conf | wc -l) != 8 ]; then echo "
"
-			echo -e "ERROR: bug ID $id - Edit\
- - Delete\n"
+			echo -n "ERROR: bug ID $id"
+			# Missing bug.conf
+			if [ ! -f "${bugdir}/${id}/bug.conf" ]; then
+				echo -n " - Missing: bug.conf"
+			fi
+			# Empty bug.conf
+			if [ -s "${bugdir}/${id}/bug.conf" ]; then
+				echo -n " - Edit"
+			else
+				echo -n " - Empty: bug.conf"
+			fi
+			echo " - Delete"
 			cat ${bugdir}/${id}/bug.conf
 			echo "
" + else + # Empty values + . ${bugdir}/${id}/bug.conf + [ -n "$BUG" ] || miss="1" + [ -n "$STATUS" ] || miss="1" + [ -n "$PRIORITY" ] || miss="1" + [ -n "$CREATOR" ] || miss="1" + [ -n "$DATE" ] || miss="1" + if [ "$miss" ]; then + echo "
"
+				echo "ERROR: bug ID $id - Empty variable(s) - Delete"
+				cat ${bugdir}/${id}/bug.conf
+				echo "
" + fi fi + unset miss done echo "$(ls -1 $bugdir | wc -l) bugs scanned" + # Check for messages consistency + echo "

Checking for empty messages

" + msgs=$(find $bugdir -name msg.* | wc -l) + empty=$(find $bugdir -name msg.* -size 0) + if [ "$empty" ]; then + echo "
"
+		cd ${bugdir}
+		for msg in */msg.*
+		do
+			if [ ! -s "$msg" ]; then
+				# Delete msg ?
+				if [ "$(GET delmsgs)" ]; then
+					echo "Deleting empty message: $(basename $bugdir)/$msg"
+					rm -f ${bugdir}/${msg}
+				else
+					echo "Found empty message: $(basename $bugdir)/$msg"
+				fi
+			fi
+		done
+		if [ ! "$(GET delmsgs)" ]; then
+			echo "--> Delete empty messages"
+		fi
+		echo "
" + fi + echo "$msgs messages scanned" + html_footer & exit 0 fi