]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/filed/fd_plugins.c
Add more plugin restore debug code.
[bacula/bacula] / bacula / src / filed / fd_plugins.c
index f0e774d61799adc024a4bb25f1c28beae1b3bb8b..0d52728dddbe69af32ea83dd16db5fe3fed0640a 100644 (file)
@@ -278,8 +278,11 @@ void plugin_name_stream(JCR *jcr, char *name)
       /*
        * End of plugin data, notify plugin, then clear flags   
        */
-      plugin = (Plugin *)jcr->plugin;
-      plug_func(plugin)->endRestoreFile((bpContext *)jcr->plugin_ctx);
+      Dmsg2(dbglvl, "End plugin data plugin=%p ctx=%p\n", jcr->plugin, jcr->plugin_ctx);
+      if (jcr->plugin) {
+         plugin = (Plugin *)jcr->plugin;
+         plug_func(plugin)->endRestoreFile((bpContext *)jcr->plugin_ctx);
+      }
       jcr->plugin_ctx = NULL;
       jcr->plugin = NULL;
       goto bail_out;
@@ -289,9 +292,10 @@ void plugin_name_stream(JCR *jcr, char *name)
     * After this point, we are dealing with a restore start
     */
 
-   Dmsg1(dbglvl, "plugin restore cmd=%s\n", cmd);
+// Dmsg1(dbglvl, "plugin restore cmd=%s\n", cmd);
    if (!(p = strchr(cmd, ':'))) {
-      Jmsg1(jcr, M_ERROR, 0, "Malformed plugin command: %s\n", cmd);
+      Jmsg1(jcr, M_ERROR, 0,
+           _("Malformed plugin command. Name not terminated by colon: %s\n"), cmd);
       goto bail_out;
    }
    len = p - cmd;
@@ -337,7 +341,8 @@ int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
    bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx;
    Plugin *plugin = (Plugin *)jcr->plugin;
    struct restore_pkt rp;
-   struct io_pkt io;
+   int flags;
+   int rc;
 
    if (!set_cmd_plugin(bfd, jcr)) {
       return CF_ERROR;
@@ -357,17 +362,31 @@ int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
    rp.where = jcr->where;
    rp.RegexWhere = jcr->RegexWhere;
    rp.replace = jcr->replace;
-   if (plug_func(plugin)->createFile(plugin_ctx, &rp) != bRC_OK) {
+   rp.create_status = CF_ERROR;
+   Dmsg1(dbglvl, "call plugin createFile=%s\n", rp.ofname);
+   rc = plug_func(plugin)->createFile(plugin_ctx, &rp);
+   if (rc != bRC_OK) {
+      Qmsg2(jcr, M_ERROR, 0, _("Plugin createFile call failed. Stat=%d file=%s\n"),
+            rc, attr->ofname);
       return CF_ERROR;
    }
-   io.pkt_size = sizeof(io);
-   io.pkt_end = sizeof(io);
-   io.func = IO_OPEN;
-   io.count = 0;
-   io.buf = NULL;
-   io.mode = 0777 & attr->statp.st_mode;
-   io.flags = O_WRONLY;
-   if (plug_func(plugin)->pluginIO(plugin_ctx, &io) != bRC_OK) {
+   if (rp.create_status == CF_ERROR) {
+      Qmsg1(jcr, M_ERROR, 0, _("Plugin createFile call failed. Returned CF_ERROR file=%s\n"),
+            attr->ofname);
+      return CF_ERROR;
+   }
+   /* Created link or directory? */
+   if (rp.create_status == CF_CREATED) {
+      return rp.create_status;        /* yes, no need to bopen */
+   }
+   flags =  O_WRONLY | O_CREAT | O_TRUNC | O_BINARY;
+   Dmsg0(dbglvl, "call bopen\n");
+   if ((bopen(bfd, attr->ofname, flags, S_IRUSR | S_IWUSR)) < 0) {
+      berrno be;
+      be.set_errno(bfd->berrno);
+      Qmsg2(jcr, M_ERROR, 0, _("Could not create %s: ERR=%s\n"),
+            attr->ofname, be.bstrerror());
+      Dmsg2(dbglvl,"Could not create %s: ERR=%s\n", attr->ofname, be.bstrerror());
       return CF_ERROR;
    }
    return CF_EXTRACT;
@@ -380,6 +399,7 @@ int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
  */
 bool plugin_set_attributes(JCR *jcr, ATTR *attr, BFILE *ofd)
 {
+   Dmsg0(dbglvl, "plugin_set_attributes\n");
    return true;
 }
 
@@ -526,6 +546,7 @@ static int my_plugin_bclose(BFILE *bfd)
       errno = io.io_errno;
       bfd->lerror = io.lerror;
    }
+   Dmsg1(dbglvl, "plugin_bclose stat=%d\n", io.status);
    return io.status;
 }