]> gitweb.fluxo.info Git - scripts.git/commitdiff
Fix: status: add status_file_changed_delta function
authorSilvio Rhatto <rhatto@riseup.net>
Sun, 4 Aug 2024 03:18:15 +0000 (00:18 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Sun, 4 Aug 2024 03:18:15 +0000 (00:18 -0300)
status

diff --git a/status b/status
index 948cba6cd7d3f0a1012f3db06c06cd58fd95a84b..b357b4efd09efed2b426f76ad5d37c1010818c53 100755 (executable)
--- a/status
+++ b/status
@@ -58,6 +58,20 @@ function status_options {
   fi
 }
 
+# Calculate timestamp delta from a file
+function status_file_changed_delta {
+  local file="$1"
+
+  if [ -z "$file" ] || [ ! -e "$file" ]; then
+    echo 0
+  fi
+
+  local file_timestamp="`stat -c '%Z' $file`"
+  local timestamp="`date +%s`"
+
+  echo $(( timestamp - file_timestamp ))
+}
+
 # Run status
 function status_run {
   if [ ! -z "$PROJECT" ]; then
@@ -84,9 +98,7 @@ function status_run {
       if [ ! -e "$mrconfig" ]; then
         mrconfig_run="1"
       else
-        local mrconfig_timestamp="`stat -c '%Z' $mrconfig`"
-        local timestamp="`date +%s`"
-        local mrconfig_age="$(( timestamp - mrconfig_timestamp ))"
+        local mrconfig_age="`status_file_changed_delta $mrconfig`"
         local mrconfig_interval="3600"
 
         # Run mrconfig-updater only every hour or so