]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/filed/fd_plugins.c
Convert restore object to use STREAM_RESTORE_OBJECT; cleaner code
[bacula/bacula] / bacula / src / filed / fd_plugins.c
index 3141fc6afdfbb561f343b133491e7d900bab2a96..4d7abba2633867a7e274bb1ff02ebd4ca074c8a0 100644 (file)
@@ -34,7 +34,7 @@
 #include "bacula.h"
 #include "filed.h"
 
-const int dbglvl = 0;
+const int dbglvl = 150;
 #ifdef HAVE_WIN32
 const char *plugin_type = "-fd.dll";
 #else
@@ -276,8 +276,8 @@ int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level)
          if (plug_func(plugin)->startBackupFile(jcr->plugin_ctx, &sp) != bRC_OK) {
             goto bail_out;
          }
-         if (sp.type == 0 || sp.fname == NULL) {
-            Jmsg1(jcr, M_FATAL, 0, _("Command plugin \"%s\" returned bad startBackupFile packet.\n"),
+         if (sp.type == 0) {
+            Jmsg1(jcr, M_FATAL, 0, _("Command plugin \"%s\": no type in startBackupFile packet.\n"),
                cmd);
             goto bail_out;
          }
@@ -287,21 +287,37 @@ int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level)
           * Copy fname and link because save_file() zaps them.  This 
           *  avoids zaping the plugin's strings.
           */
-         pm_strcpy(fname, sp.fname);
-         pm_strcpy(link, sp.link);
-         ff_pkt->fname = fname.c_str();
-         ff_pkt->link = link.c_str();
          ff_pkt->type = sp.type;
-         ff_pkt->object = sp.object;
-         ff_pkt->object_len = sp.object_len;
          if (sp.type == FT_RESTORE_FIRST) {
-            ff_pkt->LinkFI = sp.index;     /* restore object index */
+            if (!sp.object_name) {
+               Jmsg1(jcr, M_FATAL, 0, _("Command plugin \"%s\": no object_name in startBackupFile packet.\n"),
+                  cmd);
+               goto bail_out;
+            }
+            ff_pkt->fname = cmd;                 /* full plugin string */
+            ff_pkt->object_name = sp.object_name;
+            ff_pkt->object_index = sp.index;     /* restore object index */
+            ff_pkt->object_compression = 0;      /* no compression for now */
+            ff_pkt->object = sp.object;
+            ff_pkt->object_len = sp.object_len;
+         } else {
+            if (!sp.fname) {
+               Jmsg1(jcr, M_FATAL, 0, _("Command plugin \"%s\": no fname in startBackupFile packet.\n"),
+                  cmd);
+               goto bail_out;
+            }
+            pm_strcpy(fname, sp.fname);
+            pm_strcpy(link, sp.link);
+            ff_pkt->fname = fname.c_str();
+            ff_pkt->link = link.c_str();
          }
+
          memcpy(&ff_pkt->statp, &sp.statp, sizeof(ff_pkt->statp));
          Dmsg2(dbglvl, "startBackup returned type=%d, fname=%s\n", sp.type, sp.fname);
          if (sp.object) {
             Dmsg2(dbglvl, "index=%d object=%s\n", sp.index, sp.object);
          }   
+         /* Call Bacula core code to backup the plugin's file */
          save_file(jcr, ff_pkt, true);
          bRC rc = plug_func(plugin)->endBackupFile(jcr->plugin_ctx);
          if (rc == bRC_More || rc == bRC_OK) {
@@ -350,7 +366,7 @@ bool send_plugin_name(JCR *jcr, BSOCK *sd, bool start)
            sd->bstrerror());
      return false;
    }
-   Dmsg1(50, "send: %s\n", sd->msg);
+   Dmsg1(50, "send plugin name hdr: %s\n", sd->msg);
 
    if (start) {
       /* Send data -- not much */
@@ -364,7 +380,7 @@ bool send_plugin_name(JCR *jcr, BSOCK *sd, bool start)
             sd->bstrerror());
          return false;
    }
-   Dmsg1(dbglvl, "send: %s\n", sd->msg);
+   Dmsg1(dbglvl, "send plugin start/end: %s\n", sd->msg);
    sd->signal(BNET_EOD);            /* indicate end of plugin name data */
    return true;
 }
@@ -481,6 +497,7 @@ int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
    if (!plugin || !plugin_ctx || !set_cmd_plugin(bfd, jcr) || jcr->is_job_canceled()) {
       return CF_ERROR;
    }
+
    rp.pkt_size = sizeof(rp);
    rp.pkt_end = sizeof(rp);
    rp.stream = attr->stream;
@@ -517,9 +534,6 @@ int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
    if (rp.create_status == CF_CREATED) {
       return rp.create_status;        /* yes, no need to bopen */
    }
-   if (rp.type == FT_RESTORE_FIRST) {
-      return CF_CREATED;
-   }
 
    flags =  O_WRONLY | O_CREAT | O_TRUNC | O_BINARY;
    Dmsg0(dbglvl, "call bopen\n");