]> git.plutz.net Git - shellwiki/commitdiff
speed improvement: save fork when checking mdfile existence
authorPaul Hänsch <paul@plutz.net>
Sun, 21 May 2023 09:56:56 +0000 (11:56 +0200)
committerPaul Hänsch <paul@plutz.net>
Sun, 21 May 2023 09:56:56 +0000 (11:56 +0200)
handlers/20_page.sh
handlers/90_brackets.sh
themes/default.sh
tools.sh

index 87af6850279a517c957be9440221c8a0f4a4b8e2..eb894c2cda080d8b5a9c8819a86c91eea510df0f 100755 (executable)
@@ -56,7 +56,7 @@ case "${PATH_INFO}" in
     return 1
     ;;
   */)
-    if [ ! "$(mdfile "$PATH_INFO")" ]; then
+    if ! mdfile "$PATH_INFO" >&-; then
       theme_error 404
     elif ! acl_read "$PATH_INFO"; then
       theme_error 403
index 1f11cf4448697124a7b4fdfe08a2f64cc42aecae..ce49b0e9a36fd9456d74d99950da40609f5d5a1d 100755 (executable)
@@ -11,7 +11,7 @@ case "${PATH_INFO}" in
     REDIRECT "${_BASE}${PATH_INFO%\[view\]}"
     ;;
   */)
-    if [ ! "$(mdfile "${PATH_INFO}")" ]; then
+    if ! mdfile "${PATH_INFO}" >&-; then
       theme_error 404
     elif ! acl_read "${PATH_INFO}"; then
       theme_error 403
index 7c31003a1798a227f66ef384358084265c229925..3812f060b7dd1ce3d7ccb4c1b277712a40a0d139 100755 (executable)
@@ -171,7 +171,7 @@ theme_error(){
     500) printf "%s\r\n" "Status: 500 Internal Server Error";;
   esac
 
-  if [ "$(mdfile "/[wiki]/$errno/")" ]; then
+  if mdfile "/[wiki]/$errno/" >&-; then
     theme_page "/[wiki]/$errno/"
   else
     printf "Content-Length: 0\r\n\r\n"
index c5545fb92e0cecc8975627514b7d80b32ea16aff..de055fe808049e2afbc3b925a1f19f1f06413d5f 100755 (executable)
--- a/tools.sh
+++ b/tools.sh
@@ -12,15 +12,21 @@ else
 fi
 
 mdfile(){
+  #  Check if page exists, if possible fall
+  #  back to default page from installation
   local page="$(PATH "$1")"
 
   if   [ -f "$_DATA/pages/$page/#page.md" ]; then
     printf %s\\n "$_DATA/pages/$page/#page.md"
+    return 0
   elif [ -f "$_EXEC/pages/$page/#page.md" ]; then
     printf %s\\n "$_EXEC/pages/$page/#page.md"
+    return 0
   else
     return 1
-  fi
+  fi 2>&-
+  #  ^^ suppress error messages produced
+  #     by printf when stdout was closed
 }
 
 size_human(){