From fb4a1525c5736791b0ced6352faec80e2e86c61f Mon Sep 17 00:00:00 2001
From: icenine451 <benjamin.r.shelton@protonmail.com>
Date: Wed, 27 Mar 2024 09:11:52 -0400
Subject: [PATCH] Fix version change detection logic for cookers

---
 functions/checks.sh | 7 +++++++
 retrodeck.sh        | 3 ++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/functions/checks.sh b/functions/checks.sh
index c8e91a2a..e5dc89af 100644
--- a/functions/checks.sh
+++ b/functions/checks.sh
@@ -171,5 +171,12 @@ elif [[ "$new_version_major_rev" -eq "$current_version_major_rev" ]]; then
   fi
 fi
 
+# Perform post_update commands for current version if it is a cooker
+if grep -qF "cooker" <<< $hard_version; then # If newly-installed version is a "cooker" build, always perform post_update commands for current version
+  if [[ "$(echo $hard_version | cut -d'-' -f2)" == "$new_version" ]]; then
+    is_newer_version="true"
+  fi
+fi
+
 echo "$is_newer_version"
 }
diff --git a/retrodeck.sh b/retrodeck.sh
index 834ee224..cab440d7 100644
--- a/retrodeck.sh
+++ b/retrodeck.sh
@@ -102,8 +102,8 @@ done
 log d "Update triggered"
 # if lockfile exists
 if [ -f "$lockfile" ]; then
-  log d "Lockfile found but the version doesn't match with the config file"
   if [ "$hard_version" != "$version" ]; then
+    log d "Lockfile found but the version doesn't match with the config file"
     log i "Config file's version is $version but the actual version is $hard_version"
     if grep -qF "cooker" <<< $hard_version; then # If newly-installed version is a "cooker" build
       log d "Newly-installed version is a \"cooker\" build"
@@ -130,6 +130,7 @@ if [ -f "$lockfile" ]; then
                   log w "Removing RetroDECK data and starting fresh"
                   rm -rf /var
                   rm -rf "$HOME/retrodeck"
+                  rm -rf "$rdhome"
                   source /app/libexec/global.sh
                   finit
                 fi