]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Implementaion of .ls command for Plugins.
authorRadosław Korzeniewski <radekk@inteos.pl>
Thu, 11 Jan 2018 11:48:27 +0000 (12:48 +0100)
committerRadosław Korzeniewski <radekk@inteos.pl>
Wed, 25 Apr 2018 13:11:24 +0000 (15:11 +0200)
The plugin=... parameter is added to .ls command which should be the name of
the plugin with all required plugin parameters in the form found in fileset
Plugin=... directive. The plugin should implement a special listing=<path>
parameter for estimate job to use this functionality. The .ls command path=...
parameter is sent as listing=<path> for Plugin, so user can inform a Plugin
what he expecits to listing.

bacula/src/dird/fd_cmds.c
bacula/src/dird/protos.h
bacula/src/dird/ua_dotcmds.c

index 1b64be4cd4cfe1e4dbf3706dfb3975cb6e159533..ba2164edf77b4b8d528649992e7ab94b35d4f62c 100644 (file)
@@ -632,10 +632,28 @@ bool send_include_list(JCR *jcr)
 }
 
 /*
- *
+ * Send a include list with a plugin and listing=<path> parameter
+ */
+bool send_ls_plugin_fileset(JCR *jcr, const char *plugin, const char *path)
+{
+   BSOCK *fd = jcr->file_bsock;
+   fd->fsend(filesetcmd, "" /* no vss */, "" /* no snapshot */);
+
+   fd->fsend("I\n");
+   fd->fsend("O h\n");         /* is it required? */
+   fd->fsend("N\n");
+   fd->fsend("P %s listing=%s\n", plugin, path);
+   fd->fsend("N\n");
+   fd->signal(BNET_EOD);              /* end of data */
+
+   if (!response(jcr, fd, OKinc, "Include", DISPLAY_ERROR)) {
+      return false;
+   }
+   return true;
+}
+
+/*
  * Send a include list with only one directory and recurse=no
- * TODO: Need to display the plugin somewhere
- *       The main point is that we don't introduce any protocol change
  */
 bool send_ls_fileset(JCR *jcr, const char *path)
 {
index ffac125539cd8636d2eee1ec58225dac9fab7b33..bac1b68af166a47bccc2726d8fc1c2be39972df9 100644 (file)
@@ -95,6 +95,7 @@ int variable_expansion(JCR *jcr, char *inp, POOLMEM **exp);
 extern int connect_to_file_daemon(JCR *jcr, int retry_interval,
                                   int max_retry_time, int verbose);
 extern bool send_ls_fileset(JCR *jcr, const char *path);
+extern bool send_ls_plugin_fileset(JCR *jcr, const char *plugin, const char *path);
 extern bool send_include_list(JCR *jcr);
 extern bool send_exclude_list(JCR *jcr);
 extern bool send_level_command(JCR *jcr);
index 5ff3a91a5e696ba1a21dfe07bef1d92b79cecfa7..223735ca32c351e5537cc9c7f05e819edba4318f 100644 (file)
@@ -199,6 +199,7 @@ static bool dot_ls_cmd(UAContext *ua, const char *cmd)
    POOL_MEM buf;
    CLIENT *client = NULL;
    char *path = NULL;
+   char *plugin = NULL;
    JCR *jcr = ua->jcr;
    int i;
 
@@ -229,6 +230,12 @@ static bool dot_ls_cmd(UAContext *ua, const char *cmd)
       return false;
    }
 
+   /* optional plugin=... parameter */
+   i = find_arg_with_value(ua, NT_("plugin"));
+   if (i > 0) {
+      plugin = ua->argv[i];
+   }
+
    jcr->client = client;
 
    jcr->setJobType(JT_BACKUP);
@@ -243,9 +250,17 @@ static bool dot_ls_cmd(UAContext *ua, const char *cmd)
       return false;
    }
 
-   if (!send_ls_fileset(jcr, path)) {
-      ua->error_msg(_("Failed to send command to Client.\n"));
-      goto bail_out;
+   /* when .ls plugin prepare a special ls_plugin_fileset */
+   if (plugin){
+      if (!send_ls_plugin_fileset(jcr, plugin, path)) {
+         ua->error_msg(_("Failed to send plugin command to Client.\n"));
+         goto bail_out;
+      }
+   } else {
+      if (!send_ls_fileset(jcr, path)) {
+         ua->error_msg(_("Failed to send command to Client.\n"));
+         goto bail_out;
+      }
    }
 
    jcr->file_bsock->fsend("estimate listing=%d\n", 1);