Skip to content

Commit

Permalink
refactor: rename AddOptionsToFileset ...
Browse files Browse the repository at this point in the history
... to reflect addition of flags
  • Loading branch information
alaaeddineelamri authored and arogge committed Mar 2, 2023
1 parent f41571f commit 1fd9204
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 152 deletions.
2 changes: 1 addition & 1 deletion core/src/filed/fd_plugins.cc
Expand Up @@ -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;
Expand Down
302 changes: 152 additions & 150 deletions core/src/filed/fileset.cc
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
2 changes: 1 addition & 1 deletion core/src/filed/fileset.h
Expand Up @@ -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);

Expand Down

0 comments on commit 1fd9204

Please sign in to comment.