From d23009317f32e99be3c2a7c5dc91fc89c613659c Mon Sep 17 00:00:00 2001
From: obarun <eric@obarun.org>
Date: Fri, 27 Jan 2023 19:42:25 +1100
Subject: [PATCH] return to SS_DEFAULT_TREENAME if the removed tree is the
 current one

---
 src/lib66/exec/ssexec_tree.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/lib66/exec/ssexec_tree.c b/src/lib66/exec/ssexec_tree.c
index 0a32ff88..e5093f54 100644
--- a/src/lib66/exec/ssexec_tree.c
+++ b/src/lib66/exec/ssexec_tree.c
@@ -1123,7 +1123,18 @@ void tree_remove(graph_t *g, char const *base, char const *treename)
 
     tree_master_modify_contents(base, treename) ;
 
-    tree_switch_current(base, treename) ;
+    if (tree_iscurrent(base, treename)) {
+        /** this symlink must be valid in any case. If not the
+         * sanitize_system process will crash. So, at least point to
+         * the SS_DEFAULT_TREENAME as this tree is create automatically
+         * if it doesn't exist at every 66 command invocation */
+        log_warn("tree ",treename, " is marked as default -- switch default to: ", SS_DEFAULT_TREENAME) ;
+
+        if (!tree_switch_current(base, SS_DEFAULT_TREENAME))
+            log_dieusys(LOG_EXIT_SYS,"set: ", SS_DEFAULT_TREENAME, " as default") ;
+
+        log_info("Set successfully: ", SS_DEFAULT_TREENAME," as default") ;
+    }
 
     log_info("Deleted successfully: ", treename) ;
 }
-- 
GitLab