]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/runscript.c
Working directory pane in restore. Will get this into the stack next.
[bacula/bacula] / bacula / src / lib / runscript.c
index e01c1da5e246ba91bd2ffed5bdbbb85352b68c6d..871de9ebbf92529926843dafda9851efe23b9370 100644 (file)
@@ -105,6 +105,14 @@ int run_scripts(JCR *jcr, alist *runscripts, const char *label)
    bool runit;
    bool status;
 
+   int when;
+
+   if (strstr(label, NT_("Before"))) {
+      when = SCRIPT_Before;
+   } else {
+      when = SCRIPT_After;
+   }
+
    if (runscripts == NULL) {
       Dmsg0(100, "runscript: WARNING RUNSCRIPTS list is NULL\n");
       return 0;
@@ -114,28 +122,33 @@ int run_scripts(JCR *jcr, alist *runscripts, const char *label)
       Dmsg2(200, "runscript: try to run %s:%s\n", NPRT(script->target), NPRT(script->command));
       runit=false;
 
-      if ((script->when & SCRIPT_Before) && (jcr->JobStatus == JS_Created)) {
-        Dmsg0(200, "runscript: Run it because SCRIPT_Before\n");
-        runit = true;
+      if ((script->when & SCRIPT_Before) && (when & SCRIPT_Before)) {
+        if (  (script->on_success && (jcr->JobStatus == JS_Running || jcr->JobStatus == JS_Created))
+              ||
+              (script->on_failure && job_canceled(jcr))
+           )
+        {
+           Dmsg4(200, "runscript: Run it because SCRIPT_Before (%s,%i,%i,%c)\n", script->command,
+                                                                                  script->on_success,
+                                                                                  script->on_failure,
+                                                                                  jcr->JobStatus );
+
+           runit = true;
+        }
       }
 
-      if ((script->when & SCRIPT_Before) && (jcr->JobStatus == JS_Running)) {
-        Dmsg0(200, "runscript: Run it because SCRIPT_Before\n");
-        runit = true;
-      }
-
-      if (script->when & SCRIPT_After) {
-        if (  (script->on_success && (jcr->JobStatus == JS_Terminated))
-            ||
-              (script->on_failure && job_canceled(jcr))
-           )
-        {
-           Dmsg4(200, "runscript: Run it because SCRIPT_After (%s,%i,%i,%c)\n", script->command,
-                                                                                script->on_success,
-                                                                                script->on_failure,
-                                                                                jcr->JobStatus );
-           runit = true;
-        }
+      if ((script->when & SCRIPT_After) && (when & SCRIPT_After)) {
+        if (  (script->on_success && (jcr->JobStatus == JS_Terminated))
+              ||
+              (script->on_failure && job_canceled(jcr))
+           )
+        {
+           Dmsg4(200, "runscript: Run it because SCRIPT_After (%s,%i,%i,%c)\n", script->command,
+                                                                                 script->on_success,
+                                                                                 script->on_failure,
+                                                                                 jcr->JobStatus );
+           runit = true;
+        }
       }
 
       if (!script->is_local()) {
@@ -187,7 +200,7 @@ void RUNSCRIPT::set_command(const POOLMEM *cmd)
 /* set this->target to client_name */
 void RUNSCRIPT::set_target(const POOLMEM *client_name)
 {
-   Dmsg1(500, "runscript: setting target\n", NPRT(client_name));
+   Dmsg1(500, "runscript: setting target = %s\n", NPRT(client_name));
 
    if (!client_name) {
       return;