Skip to content

Commit

Permalink
Multiple "Exclude Dir Containing" Flags not honored
Browse files Browse the repository at this point in the history
It seems when implementing the Exclude Dir Containing option in the
fileset unlike every other item it doesn't allow you to specify multiple
values for this config item. Which is kind of strange and would make it
somewhat better usable. This patch adds the missing support by just
storing the values in an alist just like all others. This also fixes a
memory leak which happens when you used to specify multiple entries as
then it would overwrite the previous string dupped value with the new
value without freeing the old value.

Fixes #311: Multiple "Exclude Dir Containing" Flags not honored
  • Loading branch information
Marco van Wieringen committed Jun 17, 2014
1 parent 40f2caa commit b8282d2
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 132 deletions.
14 changes: 7 additions & 7 deletions src/dird/dird_conf.c
Expand Up @@ -1372,11 +1372,13 @@ bool FILESETRES::print_config(POOL_MEM &buff)
}

/*
* Ignore Dir Containing = entry.
* Exclude Dir Containing = entry.
*/
if (incexe->ignoredir) {
Mmsg(temp, "Ignore Dir Containing = \"%s\"\n", incexe->ignoredir);
indent_config_item(cfg_str, 2, temp.c_str());
if (incexe->ignoredir.size()) {
for (int l = 0; l < incexe->ignoredir.size(); l++) {
Mmsg(temp, "Exclude Dir Containing = \"%s\"\n", incexe->ignoredir.get(l));
indent_config_item(cfg_str, 2, temp.c_str());
}
}

indent_config_item(cfg_str, 1, "}\n");
Expand Down Expand Up @@ -1557,9 +1559,7 @@ static void free_incexe(INCEXE *incexe)
if (incexe->opts_list) {
free(incexe->opts_list);
}
if (incexe->ignoredir) {
free(incexe->ignoredir);
}
incexe->ignoredir.destroy();
free(incexe);
}

Expand Down
50 changes: 25 additions & 25 deletions src/dird/dird_conf.h
Expand Up @@ -488,33 +488,33 @@ class JOBRES : public BRSRES {
* File options structure
*/
struct FOPTS {
char opts[MAX_FOPTS]; /* options string */
alist regex; /* regex string(s) */
alist regexdir; /* regex string(s) for directories */
alist regexfile; /* regex string(s) for files */
alist wild; /* wild card strings */
alist wilddir; /* wild card strings for directories */
alist wildfile; /* wild card strings for files */
alist wildbase; /* wild card strings for files without '/' */
alist base; /* list of base names */
alist fstype; /* file system type limitation */
alist drivetype; /* drive type limitation */
alist meta; /* backup meta information */
char *reader; /* reader program */
char *writer; /* writer program */
char *plugin; /* plugin program */
char opts[MAX_FOPTS]; /* Options string */
alist regex; /* Regex string(s) */
alist regexdir; /* Regex string(s) for directories */
alist regexfile; /* Regex string(s) for files */
alist wild; /* Wild card strings */
alist wilddir; /* Wild card strings for directories */
alist wildfile; /* Wild card strings for files */
alist wildbase; /* Wild card strings for files without '/' */
alist base; /* List of base names */
alist fstype; /* File system type limitation */
alist drivetype; /* Drive type limitation */
alist meta; /* Backup meta information */
char *reader; /* Reader program */
char *writer; /* Writer program */
char *plugin; /* Plugin program */
};

/*
* This is either an include item or an exclude item
*/
struct INCEXE {
FOPTS *current_opts; /* points to current options structure */
FOPTS **opts_list; /* options list */
int32_t num_opts; /* number of options items */
alist name_list; /* filename list -- holds char * */
alist plugin_list; /* filename list for plugins */
char *ignoredir; /* ignoredir string */
FOPTS *current_opts; /* Points to current options structure */
FOPTS **opts_list; /* Options list */
int32_t num_opts; /* Number of options items */
alist name_list; /* Filename list -- holds char * */
alist plugin_list; /* Filename list for plugins */
alist ignoredir; /* Ignoredir string */
};

/*
Expand All @@ -525,13 +525,13 @@ class FILESETRES {
RES hdr;

bool new_include; /* Set if new include used */
INCEXE **include_items; /* array of incexe structures */
int32_t num_includes; /* number in array */
INCEXE **include_items; /* Array of incexe structures */
int32_t num_includes; /* Number in array */
INCEXE **exclude_items;
int32_t num_excludes;
bool have_MD5; /* set if MD5 initialized */
bool have_MD5; /* Set if MD5 initialized */
struct MD5Context md5c; /* MD5 of include/exclude */
char MD5[30]; /* base 64 representation of MD5 */
char MD5[30]; /* Base 64 representation of MD5 */
bool ignore_fs_changes; /* Don't force Full if FS changed */
bool enable_vss; /* Enable Volume Shadow Copy */

Expand Down
8 changes: 4 additions & 4 deletions src/dird/fd_cmds.c
Expand Up @@ -282,16 +282,16 @@ static bool send_fileset(JCR *jcr)
fd->fsend("E\n");
}

if (ie->ignoredir) {
fd->fsend("Z %s\n", ie->ignoredir);
for (int j = 0; j < ie->ignoredir.size(); j++) {
fd->fsend("Z %s\n", ie->ignoredir.get(j));
}

for (int j = 0; j < ie->num_opts; j++) {
FOPTS *fo = ie->opts_list[j];
bool enhanced_wild = false;

for (int k = 0; fo->opts[k] != '\0'; k++) {
if (fo->opts[k]=='W') {
if (fo->opts[k] == 'W') {
enhanced_wild = true;
break;
}
Expand All @@ -302,7 +302,7 @@ static bool send_fileset(JCR *jcr)
*/
if (store && !store->AllowCompress) {
char newopts[MAX_FOPTS];
bool done=false; /* print warning only if compression enabled in FS */
bool done = false; /* print warning only if compression enabled in FS */
int l = 0;

for (int k = 0; fo->opts[k] != '\0'; k++) {
Expand Down
4 changes: 3 additions & 1 deletion src/dird/inc_conf.c
Expand Up @@ -647,10 +647,12 @@ static void store_excludedir(LEX *lc, RES_ITEM *item, int index, int pass, bool
if (exclude) {
scan_err0(lc, _("ExcludeDirContaining directive not permitted in Exclude.\n"));
/* NOT REACHED */
return;
}

lex_get_token(lc, T_NAME);
if (pass == 1) {
res_incexe.ignoredir = bstrdup(lc->str);
res_incexe.ignoredir.append(bstrdup(lc->str));
}
scan_to_eol(lc);
}
Expand Down
8 changes: 2 additions & 6 deletions src/filed/dir_cmd.c
Expand Up @@ -353,9 +353,7 @@ static inline void cleanup_fileset(JCR *jcr)
incexe->opts_list.destroy();
incexe->name_list.destroy();
incexe->plugin_list.destroy();
if (incexe->ignoredir) {
free(incexe->ignoredir);
}
incexe->ignoredir.destroy();
}
fileset->include_list.destroy();

Expand Down Expand Up @@ -383,9 +381,7 @@ static inline void cleanup_fileset(JCR *jcr)
incexe->opts_list.destroy();
incexe->name_list.destroy();
incexe->plugin_list.destroy();
if (incexe->ignoredir) {
free(incexe->ignoredir);
}
incexe->ignoredir.destroy();
}
fileset->exclude_list.destroy();
free(fileset);
Expand Down
11 changes: 7 additions & 4 deletions src/filed/fileset.c
Expand Up @@ -433,7 +433,7 @@ void add_fileset(JCR *jcr, const char *item)
break;
case 'Z': /* Ignore dir */
state = state_include;
fileset->incexe->ignoredir = bstrdup(item);
fileset->incexe->ignoredir.append(bstrdup(item));
break;
case 'D':
current_opts = start_options(ff);
Expand Down Expand Up @@ -469,6 +469,7 @@ bool term_fileset(JCR *jcr)

#ifdef xxx_DEBUG_CODE
for (int i = 0; i < fileset->include_list.size(); i++) {
dlistString *node;
findINCEXE *incexe = (findINCEXE *)fileset->include_list.get(i);

Dmsg0(400, "I\n");
Expand Down Expand Up @@ -509,13 +510,15 @@ bool term_fileset(JCR *jcr)
Dmsg1(400, "G %s\n", (char *)fo->plugin);
}
}
if (incexe->ignoredir) {
Dmsg1(400, "Z %s\n", incexe->ignoredir);

for (int k = 0; k < incexe->ignoredir.size(); k++) {
Dmsg1(400, "Z %s\n", (char *)incexe->ignoredir.get(k));
}
dlistString *node;

foreach_dlist(node, &incexe->name_list) {
Dmsg1(400, "F %s\n", node->c_str());
}

foreach_dlist(node, &incexe->plugin_list) {
Dmsg1(400, "P %s\n", node->c_str());
}
Expand Down

0 comments on commit b8282d2

Please sign in to comment.