Browse Source

Implement a locking mechanism to avoid multiple update prompts (fixes #3766)

Fabian Wolff 7 years ago
parent
commit
40bfe5a412
1 changed files with 23 additions and 18 deletions
  1. 23 18
      tools/check_for_upgrade.sh

+ 23 - 18
tools/check_for_upgrade.sh

@@ -29,31 +29,36 @@ fi
 # Cancel upgrade if git is unavailable on the system
 whence git >/dev/null || return 0
 
-if [ -f ~/.zsh-update ]
+if mkdir "$ZSH/log/update.lock" 2>/dev/null
 then
-  . ~/.zsh-update
+  if [ -f ~/.zsh-update ]
+  then
+    . ~/.zsh-update
 
-  if [[ -z "$LAST_EPOCH" ]]; then
-    _update_zsh_update && return 0;
-  fi
+    if [[ -z "$LAST_EPOCH" ]]; then
+      _update_zsh_update && return 0;
+    fi
 
-  epoch_diff=$(($(_current_epoch) - $LAST_EPOCH))
-  if [ $epoch_diff -gt $epoch_target ]
-  then
-    if [ "$DISABLE_UPDATE_PROMPT" = "true" ]
+    epoch_diff=$(($(_current_epoch) - $LAST_EPOCH))
+    if [ $epoch_diff -gt $epoch_target ]
     then
-      _upgrade_zsh
-    else
-      echo "[Oh My Zsh] Would you like to check for updates? [Y/n]: \c"
-      read line
-      if [[ "$line" == Y* ]] || [[ "$line" == y* ]] || [ -z "$line" ]; then
+      if [ "$DISABLE_UPDATE_PROMPT" = "true" ]
+      then
         _upgrade_zsh
       else
-        _update_zsh_update
+        echo "[Oh My Zsh] Would you like to check for updates? [Y/n]: \c"
+        read line
+        if [[ "$line" == Y* ]] || [[ "$line" == y* ]] || [ -z "$line" ]; then
+          _upgrade_zsh
+        else
+          _update_zsh_update
+        fi
       fi
     fi
+  else
+    # create the zsh file
+    _update_zsh_update
   fi
-else
-  # create the zsh file
-  _update_zsh_update
+
+  rm -r $ZSH/log/update.lock
 fi