From 1fd9204b032b82971c1cf53b0733541328ce5f08 Mon Sep 17 00:00:00 2001 From: Alaa Eddine Elamri Date: Fri, 23 Dec 2022 15:33:43 +0100 Subject: [PATCH] refactor: rename `AddOptionsToFileset` ... ... to reflect addition of flags --- core/src/filed/fd_plugins.cc | 2 +- core/src/filed/fileset.cc | 302 ++++++++++++++++++----------------- core/src/filed/fileset.h | 2 +- 3 files changed, 154 insertions(+), 152 deletions(-) diff --git a/core/src/filed/fd_plugins.cc b/core/src/filed/fd_plugins.cc index 4ef5622d79f..840613847ba 100644 --- a/core/src/filed/fd_plugins.cc +++ b/core/src/filed/fd_plugins.cc @@ -2334,7 +2334,7 @@ static bRC bareosAddOptions(PluginContext* ctx, const char* opts) if (!IsCtxGood(ctx, jcr, bctx)) { return bRC_Error; } if (!opts) { return bRC_Error; } - AddOptionsToFileset(jcr, opts); + AddOptionsFlagsToFileset(jcr, opts); Dmsg1(1000, "Add options=%s\n", opts); return bRC_OK; diff --git a/core/src/filed/fileset.cc b/core/src/filed/fileset.cc index 468f37abedd..5bdfa0672e1 100644 --- a/core/src/filed/fileset.cc +++ b/core/src/filed/fileset.cc @@ -33,6 +33,7 @@ #include "filed/filed.h" #include "filed/filed_globals.h" #include "filed/filed_jcr_impl.h" +#include "filed/fileset.h" #include "findlib/match.h" #include "lib/berrno.h" #include "lib/edit.h" @@ -45,9 +46,6 @@ namespace filedaemon { -/* Forward referenced functions */ -static int SetOptions(findFOPTS* fo, const char* opts); - /** * callback function for edit_job_codes * See ../lib/util.c, function edit_job_codes, for more remaining codes @@ -243,158 +241,12 @@ int AddWildToFileset(JobControlRecord* jcr, const char* item, int type) return state_options; } -// Add options to the current fileset -int AddOptionsToFileset(JobControlRecord* jcr, const char* item) -{ - findFOPTS* current_opts = start_options(jcr->fd_impl->ff); - - SetOptions(current_opts, item); - - return state_options; -} - -void AddFileset(JobControlRecord* jcr, const char* item) -{ - FindFilesPacket* ff = jcr->fd_impl->ff; - findFILESET* fileset = ff->fileset; - int code, subcode; - int state = fileset->state; - findFOPTS* current_opts; - - // Get code, optional subcode, and position item past the dividing space - Dmsg1(100, "%s\n", item); - code = item[0]; - if (code != '\0') { ++item; } - - subcode = ' '; /* A space is always a valid subcode */ - if (item[0] != '\0' && item[0] != ' ') { - subcode = item[0]; - ++item; - } - - if (*item == ' ') { ++item; } - - // Skip all lines we receive after an error - if (state == state_error) { - Dmsg0(100, "State=error return\n"); - return; - } - - /* The switch tests the code for validity. - * The subcode is always good if it is a space, otherwise we must confirm. - * We set state to state_error first assuming the subcode is invalid, - * requiring state to be set in cases below that handle subcodes. */ - if (subcode != ' ') { - state = state_error; - Dmsg0(100, "Set state=error or double code.\n"); - } - switch (code) { - case 'I': - (void)new_include(jcr->fd_impl->ff->fileset); - break; - case 'E': - (void)new_exclude(jcr->fd_impl->ff->fileset); - break; - case 'N': /* Null */ - state = state_none; - break; - case 'F': /* File */ - state = state_include; - AddFileToFileset(jcr, item, true, jcr->fd_impl->ff->fileset); - break; - case 'P': /* Plugin */ - state = state_include; - AddFileToFileset(jcr, item, false, jcr->fd_impl->ff->fileset); - break; - case 'R': /* Regex */ - state = AddRegexToFileset(jcr, item, subcode); - break; - case 'B': - current_opts = start_options(ff); - current_opts->base.append(strdup(item)); - state = state_options; - break; - case 'X': /* Filetype or Drive type */ - current_opts = start_options(ff); - state = state_options; - if (subcode == ' ') { - current_opts->fstype.append(strdup(item)); - } else if (subcode == 'D') { - current_opts->Drivetype.append(strdup(item)); - } else { - state = state_error; - } - break; - case 'W': /* Wild cards */ - state = AddWildToFileset(jcr, item, subcode); - break; - case 'O': /* Options */ - state = AddOptionsToFileset(jcr, item); - break; - case 'Z': /* Ignore dir */ - state = state_include; - fileset->incexe->ignoredir.append(strdup(item)); - break; - case 'D': - current_opts = start_options(ff); - state = state_options; - break; - case 'T': - current_opts = start_options(ff); - state = state_options; - break; - case 'G': /* Plugin command for this Option block */ - current_opts = start_options(ff); - current_opts->plugin = strdup(item); - state = state_options; - break; - default: - Jmsg(jcr, M_FATAL, 0, _("Invalid FileSet command: %s\n"), item); - state = state_error; - break; - } - ff->fileset->state = state; -} - -bool TermFileset(JobControlRecord* jcr) -{ - findFILESET* fileset; - - fileset = jcr->fd_impl->ff->fileset; -#ifdef HAVE_WIN32 - /* Expand the fileset to include all drive letters when the fileset includes a - * File = / entry. */ - if (!expand_win32_fileset(jcr->fd_impl->ff->fileset)) { return false; } - - // Exclude entries in NotToBackup registry key - if (!exclude_win32_not_to_backup_registry_entries(jcr, jcr->fd_impl->ff)) { - return false; - } -#endif - - // Generate bEventPluginCommand events for each Options Plugin. - for (int i = 0; i < fileset->include_list.size(); i++) { - findIncludeExcludeItem* incexe - = (findIncludeExcludeItem*)fileset->include_list.get(i); - - for (int j = 0; j < incexe->opts_list.size(); j++) { - findFOPTS* fo = (findFOPTS*)incexe->opts_list.get(j); - - if (fo->plugin) { - GeneratePluginEvent(jcr, bEventPluginCommand, (void*)fo->plugin); - } - } - } - - return jcr->fd_impl->ff->fileset->state != state_error; -} - /** * As an optimization, we should do this during * "compile" time in filed/job.c, and keep only a bit mask * and the Verify options. */ -static int SetOptions(findFOPTS* fo, const char* opts) +static int SetOptionsAndFlags(findFOPTS* fo, const char* opts) { int j; const char* p; @@ -662,4 +514,154 @@ static int SetOptions(findFOPTS* fo, const char* opts) return state_options; } + +// Add options to the current fileset +int AddOptionsFlagsToFileset(JobControlRecord* jcr, const char* item) +{ + findFOPTS* current_opts = start_options(jcr->fd_impl->ff); + + SetOptionsAndFlags(current_opts, item); + + return state_options; +} + +void AddFileset(JobControlRecord* jcr, const char* item) +{ + FindFilesPacket* ff = jcr->fd_impl->ff; + findFILESET* fileset = ff->fileset; + int code, subcode; + int state = fileset->state; + findFOPTS* current_opts; + + // Get code, optional subcode, and position item past the dividing space + Dmsg1(100, "%s\n", item); + code = item[0]; + if (code != '\0') { ++item; } + + subcode = ' '; /* A space is always a valid subcode */ + if (item[0] != '\0' && item[0] != ' ') { + subcode = item[0]; + ++item; + } + + if (*item == ' ') { ++item; } + + // Skip all lines we receive after an error + if (state == state_error) { + Dmsg0(100, "State=error return\n"); + return; + } + + /** + * The switch tests the code for validity. + * The subcode is always good if it is a space, otherwise we must confirm. + * We set state to state_error first assuming the subcode is invalid, + * requiring state to be set in cases below that handle subcodes. + */ + if (subcode != ' ') { + state = state_error; + Dmsg0(100, "Set state=error or double code.\n"); + } + switch (code) { + case 'I': + (void)new_include(jcr->fd_impl->ff->fileset); + break; + case 'E': + (void)new_exclude(jcr->fd_impl->ff->fileset); + break; + case 'N': /* Null */ + state = state_none; + break; + case 'F': /* File */ + state = state_include; + AddFileToFileset(jcr, item, true, jcr->fd_impl->ff->fileset); + break; + case 'P': /* Plugin */ + state = state_include; + AddFileToFileset(jcr, item, false, jcr->fd_impl->ff->fileset); + break; + case 'R': /* Regex */ + state = AddRegexToFileset(jcr, item, subcode); + break; + case 'B': + current_opts = start_options(ff); + current_opts->base.append(strdup(item)); + state = state_options; + break; + case 'X': /* Filetype or Drive type */ + current_opts = start_options(ff); + state = state_options; + if (subcode == ' ') { + current_opts->fstype.append(strdup(item)); + } else if (subcode == 'D') { + current_opts->Drivetype.append(strdup(item)); + } else { + state = state_error; + } + break; + case 'W': /* Wild cards */ + state = AddWildToFileset(jcr, item, subcode); + break; + case 'O': /* Options */ + state = AddOptionsFlagsToFileset(jcr, item); + break; + case 'Z': /* Ignore dir */ + state = state_include; + fileset->incexe->ignoredir.append(strdup(item)); + break; + case 'D': + current_opts = start_options(ff); + state = state_options; + break; + case 'T': + current_opts = start_options(ff); + state = state_options; + break; + case 'G': /* Plugin command for this Option block */ + current_opts = start_options(ff); + current_opts->plugin = strdup(item); + state = state_options; + break; + default: + Jmsg(jcr, M_FATAL, 0, _("Invalid FileSet command: %s\n"), item); + state = state_error; + break; + } + ff->fileset->state = state; +} + +bool TermFileset(JobControlRecord* jcr) +{ + findFILESET* fileset; + + fileset = jcr->fd_impl->ff->fileset; +#ifdef HAVE_WIN32 + /* + * Expand the fileset to include all drive letters when the fileset includes a + * File = / entry. + */ + if (!expand_win32_fileset(jcr->fd_impl->ff->fileset)) { return false; } + + // Exclude entries in NotToBackup registry key + if (!exclude_win32_not_to_backup_registry_entries(jcr, jcr->fd_impl->ff)) { + return false; + } +#endif + + // Generate bEventPluginCommand events for each Options Plugin. + for (int i = 0; i < fileset->include_list.size(); i++) { + findIncludeExcludeItem* incexe + = (findIncludeExcludeItem*)fileset->include_list.get(i); + + for (int j = 0; j < incexe->opts_list.size(); j++) { + findFOPTS* fo = (findFOPTS*)incexe->opts_list.get(j); + + if (fo->plugin) { + GeneratePluginEvent(jcr, bEventPluginCommand, (void*)fo->plugin); + } + } + } + + return jcr->fd_impl->ff->fileset->state != state_error; +} } /* namespace filedaemon */ diff --git a/core/src/filed/fileset.h b/core/src/filed/fileset.h index 62944ef3663..db8a3197e59 100644 --- a/core/src/filed/fileset.h +++ b/core/src/filed/fileset.h @@ -35,7 +35,7 @@ findIncludeExcludeItem* get_incexe(JobControlRecord* jcr); void SetIncexe(JobControlRecord* jcr, findIncludeExcludeItem* incexe); int AddRegexToFileset(JobControlRecord* jcr, const char* item, int type); int AddWildToFileset(JobControlRecord* jcr, const char* item, int type); -int AddOptionsToFileset(JobControlRecord* jcr, const char* item); +int AddOptionsFlagsToFileset(JobControlRecord* jcr, const char* item); void AddFileset(JobControlRecord* jcr, const char* item); bool TermFileset(JobControlRecord* jcr);