From: Radosław Korzeniewski Date: Thu, 11 Jan 2018 11:48:27 +0000 (+0100) Subject: Implementaion of .ls command for Plugins. X-Git-Tag: Release-9.2.0~84 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6563a26196b2197d9e65ec25d3bb3f2953ceaf09;p=thirdparty%2Fbacula.git Implementaion of .ls command for Plugins. 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= parameter for estimate job to use this functionality. The .ls command path=... parameter is sent as listing= for Plugin, so user can inform a Plugin what he expecits to listing. --- diff --git a/bacula/src/dird/fd_cmds.c b/bacula/src/dird/fd_cmds.c index 1b64be4cd4..ba2164edf7 100644 --- a/bacula/src/dird/fd_cmds.c +++ b/bacula/src/dird/fd_cmds.c @@ -632,10 +632,28 @@ bool send_include_list(JCR *jcr) } /* - * + * Send a include list with a plugin and listing= 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) { diff --git a/bacula/src/dird/protos.h b/bacula/src/dird/protos.h index ffac125539..bac1b68af1 100644 --- a/bacula/src/dird/protos.h +++ b/bacula/src/dird/protos.h @@ -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); diff --git a/bacula/src/dird/ua_dotcmds.c b/bacula/src/dird/ua_dotcmds.c index 5ff3a91a5e..223735ca32 100644 --- a/bacula/src/dird/ua_dotcmds.c +++ b/bacula/src/dird/ua_dotcmds.c @@ -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);