From 22e420d4656b7a173627e5ec5a381bf847d5ad1e Mon Sep 17 00:00:00 2001
From: "Leigh B. Stoller" <stoller@flux.utah.edu>
Date: Fri, 21 Sep 2007 21:21:18 +0000
Subject: [PATCH] If the template being modified is "active" then move the
 active bit to the child template (parent no longer active).

---
 tbsetup/Template.pm.in     | 12 ++++++++++++
 tbsetup/template_create.in |  9 +++++++++
 2 files changed, 21 insertions(+)

diff --git a/tbsetup/Template.pm.in b/tbsetup/Template.pm.in
index 6bad738e07..65997c4a9f 100644
--- a/tbsetup/Template.pm.in
+++ b/tbsetup/Template.pm.in
@@ -173,6 +173,8 @@ sub logfile($) {
     return ((! ref($_[0])) ? -1 : $_[0]->{'TEMPLATE'}->{'logfile'}); }
 sub logfile_open($) {
     return ((! ref($_[0])) ? -1 : $_[0]->{'TEMPLATE'}->{'logfile_open'}); }
+sub active($) {
+    return ((! ref($_[0])) ? -1 : $_[0]->{'TEMPLATE'}->{'active'}); }
 
 #
 # Lookup a template given an experiment index.
@@ -1776,6 +1778,16 @@ sub InActivate($)
 
     return 0;
 }
+sub IsActive($)
+{
+    my ($self) = @_;
+
+    # Must be a real reference. 
+    return -1
+	if (! ref($self));
+
+    return $self->active();
+}
 
 # Improve this at some point.
 sub Recurse($$)
diff --git a/tbsetup/template_create.in b/tbsetup/template_create.in
index b46adddd66..a5278dd496 100644
--- a/tbsetup/template_create.in
+++ b/tbsetup/template_create.in
@@ -786,6 +786,15 @@ system("$makegraph $guid");
 fatal(-1, "Error generating template graph.")
     if ($?);
 
+#
+# Make the new template active (and the parent template inactive) if the
+# parent was already active.
+#
+if ($parent_template->IsActive()) {
+    $parent_template->InActivate();
+    $template->Activate();
+}
+
 #
 # Update parent to point to most recent child.
 #
-- 
GitLab