/* Dump contents of resource */
void dump_resource(int type, RES *reshdr, void sendit(void *sock, char *fmt, ...), void *sock)
{
- int i;
URES *res = (URES *)reshdr;
int recurse = 1;
break;
case R_FILESET:
sendit(sock, "FileSet: name=%s\n", res->res_fs.hdr.name);
- for (i=0; i<res->res_fs.num_includes; i++)
- sendit(sock, " Inc: %s\n", res->res_fs.include_array[i]->name);
- for (i=0; i<res->res_fs.num_excludes; i++)
- sendit(sock, " Exc: %s\n", res->res_fs.exclude_array[i]->name);
+ for (int i=0; i<res->res_fs.num_includes; i++) {
+ INCEXE *incexe = res->res_fs.include_items[i];
+ for (int j=0; j<incexe->num_names; j++) {
+ sendit(sock, " Inc: %s\n", incexe->name_list[j]);
+ }
+ }
+ for (int i=0; i<res->res_fs.num_excludes; i++) {
+ INCEXE *incexe = res->res_fs.exclude_items[i];
+ for (int j=0; j<incexe->num_names; j++) {
+ sendit(sock, " Exc: %s\n", incexe->name_list[j]);
+ }
+ }
break;
case R_SCHEDULE:
if (res->res_sch.run) {
case R_FILESET:
if ((num=res->res_fs.num_includes)) {
while (--num >= 0) {
- free(res->res_fs.include_array[num]);
+ INCEXE *incexe = res->res_fs.include_items[num];
+ for (int i=0; i<incexe->num_names; i++) {
+ free(incexe->name_list[i]);
+ }
+ if (incexe->name_list) {
+ free(incexe->name_list);
+ }
+ free(incexe);
}
- free(res->res_fs.include_array);
+ free(res->res_fs.include_items);
}
+ res->res_fs.num_includes = 0;
if ((num=res->res_fs.num_excludes)) {
while (--num >= 0) {
- free(res->res_fs.exclude_array[num]);
+ INCEXE *incexe = res->res_fs.exclude_items[num];
+ for (int i=0; i<incexe->num_names; i++) {
+ free(incexe->name_list[i]);
+ }
+ if (incexe->name_list) {
+ free(incexe->name_list);
+ }
+ free(incexe);
}
- free(res->res_fs.exclude_array);
+ free(res->res_fs.exclude_items);
}
+ res->res_fs.num_excludes = 0;
break;
case R_POOL:
if (res->res_pool.pool_type) {
/* Resources not containing a resource */
case R_CATALOG:
case R_STORAGE:
- case R_FILESET:
+ case R_FILEOPTIONS:
case R_GROUP:
case R_POOL:
case R_MSGS:
break;
- /* Special case for FileOptions, all allocations are done
- * only in pass 2, so here we must copy the whole structure
+ /* Special case for FileSet, all allocations are done
+ * only in pass 2, so here we must copy the whole structure.
+ * This is done so that we can have forward references to
+ * FileOptions resources within the fileset
*/
- case R_FILEOPTIONS:
+ case R_FILESET:
RES res_save;
- if ((res = (URES *)GetResWithName(R_FILEOPTIONS, res_all.res_dir.hdr.name)) == NULL) {
- Emsg1(M_ERROR_TERM, 0, "Cannot find FileOptions resource %s\n", res_all.res_dir.hdr.name);
+ if ((res = (URES *)GetResWithName(R_FILESET, res_all.res_dir.hdr.name)) == NULL) {
+ Emsg1(M_ERROR_TERM, 0, "Cannot find FileSet resource %s\n", res_all.res_dir.hdr.name);
}
memcpy(&res_save, &res_all, sizeof(RES));
memcpy(&res_all, res, sizeof(RES));
- memcpy(res, &res_all, sizeof(FILEOPTIONS));
+ memcpy(res, &res_all, sizeof(FILESET));
memcpy(&res_all, &res_save, sizeof(RES));
break;
}
}
if (!inc_opts[0]) {
- strcat(inc_opts, "0 "); /* set no options */
- } else {
- strcat(inc_opts, " "); /* add field separator */
+ strcat(inc_opts, "0"); /* set no options */
}
inc_opts_len = strlen(inc_opts);
- if (pass == 1) {
+ if (pass == 2) {
+ INCEXE *incexe;
if (!res_all.res_fs.have_MD5) {
MD5Init(&res_all.res_fs.md5c);
res_all.res_fs.have_MD5 = TRUE;
}
+ /* Create incexe structure */
+ Dmsg0(200, "Create INCEXE structure\n");
+ incexe = (INCEXE *)malloc(sizeof(INCEXE));
+ memset(incexe, 0, sizeof(INCEXE));
+ bstrncpy(incexe->opts, inc_opts, sizeof(incexe->opts));
+ incexe->fileopts = (struct s_res_fopts *)res;
+ Dmsg1(200, "incexe opts=%s\n", incexe->opts);
+ if (item->code == 0) { /* include */
+ if (res_all.res_fs.num_includes == 0) {
+ res_all.res_fs.include_items = (INCEXE **)malloc(sizeof(INCEXE *));
+ } else {
+ res_all.res_fs.include_items = (INCEXE **)realloc(res_all.res_fs.include_items,
+ sizeof(INCEXE *) * res_all.res_fs.num_includes + 1);
+ }
+ res_all.res_fs.include_items[res_all.res_fs.num_includes++] = incexe;
+ Dmsg1(200, "num_includes=%d\n", res_all.res_fs.num_includes);
+ } else { /* exclude */
+ if (res_all.res_fs.num_excludes == 0) {
+ res_all.res_fs.exclude_items = (INCEXE **)malloc(sizeof(INCEXE *));
+ } else {
+ res_all.res_fs.exclude_items = (INCEXE **)realloc(res_all.res_fs.exclude_items,
+ sizeof(INCEXE *) * res_all.res_fs.num_excludes + 1);
+ }
+ res_all.res_fs.exclude_items[res_all.res_fs.num_excludes++] = incexe;
+ Dmsg1(200, "num_excludes=%d\n", res_all.res_fs.num_excludes);
+ }
+
/* Pickup include/exclude names. They are stored in INCEXE
* structures which contains the options and the name.
*/
case T_IDENTIFIER:
case T_UNQUOTED_STRING:
case T_QUOTED_STRING:
- INCEXE *incexe;
- incexe = (INCEXE *)malloc(lc->str_len + sizeof(INCEXE));
- memset(incexe, 0, sizeof(INCEXE));
- bstrncpy(incexe->opts, inc_opts, sizeof(incexe->opts));
- strcpy(incexe->name, lc->str);
- incexe->fileopts = (struct s_res_fopts *)res;
- incexe->num_fileopts = 1;
-
if (res_all.res_fs.have_MD5) {
- MD5Update(&res_all.res_fs.md5c, (unsigned char *)incexe,
- sizeof(INCEXE) + lc->str_len);
+ MD5Update(&res_all.res_fs.md5c, (unsigned char *)lc->str, lc->str_len);
}
- if (item->code == 0) { /* include */
- if (res_all.res_fs.num_includes == res_all.res_fs.include_size) {
- res_all.res_fs.include_size += 10;
- if (res_all.res_fs.include_array == NULL) {
- res_all.res_fs.include_array = (INCEXE **)malloc(sizeof(INCEXE *) * res_all.res_fs.include_size);
- } else {
- res_all.res_fs.include_array = (INCEXE **)realloc(res_all.res_fs.include_array,
- sizeof(INCEXE *) * res_all.res_fs.include_size);
- }
- }
- res_all.res_fs.include_array[res_all.res_fs.num_includes++] = incexe;
- } else { /* exclude */
- if (res_all.res_fs.num_excludes == res_all.res_fs.exclude_size) {
- res_all.res_fs.exclude_size += 10;
- if (res_all.res_fs.exclude_array == NULL) {
- res_all.res_fs.exclude_array = (INCEXE **)malloc(sizeof(INCEXE *) * res_all.res_fs.exclude_size);
- } else {
- res_all.res_fs.exclude_array = (INCEXE **)realloc(res_all.res_fs.exclude_array,
- sizeof(INCEXE *) * res_all.res_fs.exclude_size);
- }
+ if (incexe->num_names == incexe->max_names) {
+ incexe->max_names += 10;
+ if (incexe->name_list == NULL) {
+ incexe->name_list = (char **)malloc(sizeof(char *) * incexe->max_names);
+ } else {
+ incexe->name_list = (char **)realloc(incexe->name_list,
+ sizeof(char *) * incexe->max_names);
}
- res_all.res_fs.exclude_array[res_all.res_fs.num_excludes++] = incexe;
}
+ incexe->name_list[incexe->num_names++] = bstrdup(lc->str);
+ Dmsg1(200, "Add to name_list %s\n", incexe->name_list[incexe->num_names -1]);
break;
default:
scan_err1(lc, "Expected a filename, got: %s", lc->str);
}
}
- } else { /* pass 2 */
+ /* Note, MD5Final is done in backup.c */
+ } else { /* pass 1 */
while (lex_get_token(lc, T_ALL) != T_EOB)
{}
}
int token;
char *match;
- if (pass == 2) {
+ if (pass == 1) {
/* Pickup Match string
*/
token = lex_get_token(lc, T_ALL);
default:
scan_err1(lc, "Expected a filename, got: %s", lc->str);
}
- } else { /* pass 1 */
+ } else { /* pass 2 */
lex_get_token(lc, T_ALL);
}
scan_to_eol(lc);
{
FILESET *fileset;
BSOCK *fd;
- int i;
fd = jcr->file_bsock;
fileset = jcr->fileset;
fd->msglen = sprintf(fd->msg, inc);
bnet_send(fd);
- for (i=0; i < fileset->num_includes; i++) {
+ for (int i=0; i < fileset->num_includes; i++) {
BPIPE *bpipe;
FILE *ffd;
char buf[1000];
int optlen, stat;
INCEXE *ie;
- Dmsg1(120, "dird>filed: include file: %s\n", fileset->include_array[i]);
- ie = fileset->include_array[i];
- p = ie->name;
- switch (*p++) {
- case '|':
- fd->msg = edit_job_codes(jcr, fd->msg, p, "");
- bpipe = open_bpipe(fd->msg, 0, "r");
- if (!bpipe) {
- Jmsg(jcr, M_FATAL, 0, _("Cannot run program: %s. ERR=%s\n"),
- p, strerror(errno));
- goto bail_out;
- }
- /* Copy File options */
- strcpy(buf, ie->opts);
- optlen = strlen(buf);
- while (fgets(buf+optlen, sizeof(buf)-optlen, bpipe->rfd)) {
- fd->msglen = Mmsg(&fd->msg, "%s", buf);
- Dmsg2(200, "Including len=%d: %s", fd->msglen, fd->msg);
- if (!bnet_send(fd)) {
- Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
+ ie = fileset->include_items[i];
+ for (int j=0; j<ie->num_names; j++) {
+ p = ie->name_list[j];
+ switch (*p++) {
+ case '|':
+ fd->msg = edit_job_codes(jcr, fd->msg, p, "");
+ bpipe = open_bpipe(fd->msg, 0, "r");
+ if (!bpipe) {
+ Jmsg(jcr, M_FATAL, 0, _("Cannot run program: %s. ERR=%s\n"),
+ p, strerror(errno));
goto bail_out;
}
- }
- if ((stat=close_bpipe(bpipe)) != 0) {
- Jmsg(jcr, M_FATAL, 0, _("Error running program: %s. RtnStat=%d ERR=%s\n"),
- p, stat, strerror(errno));
- goto bail_out;
- }
- break;
- case '<':
- if ((ffd = fopen(p, "r")) == NULL) {
- Jmsg(jcr, M_FATAL, 0, _("Cannot open included file: %s. ERR=%s\n"),
- p, strerror(errno));
- goto bail_out;
- }
- /* Copy File options */
- strcpy(buf, ie->opts);
- optlen = strlen(buf);
- while (fgets(buf+optlen, sizeof(buf)-optlen, ffd)) {
- fd->msglen = Mmsg(&fd->msg, "%s", buf);
+ /* Copy File options */
+ if (ie->fileopts) {
+ strcpy(buf, ie->fileopts->opts);
+ } else {
+ strcpy(buf, ie->opts);
+ }
+ strcat(buf, " ");
+ optlen = strlen(buf);
+ while (fgets(buf+optlen, sizeof(buf)-optlen, bpipe->rfd)) {
+ fd->msglen = Mmsg(&fd->msg, "%s", buf);
+ Dmsg2(200, "Including len=%d: %s", fd->msglen, fd->msg);
+ if (!bnet_send(fd)) {
+ Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
+ goto bail_out;
+ }
+ }
+ if ((stat=close_bpipe(bpipe)) != 0) {
+ Jmsg(jcr, M_FATAL, 0, _("Error running program: %s. RtnStat=%d ERR=%s\n"),
+ p, stat, strerror(errno));
+ goto bail_out;
+ }
+ break;
+ case '<':
+ if ((ffd = fopen(p, "r")) == NULL) {
+ Jmsg(jcr, M_FATAL, 0, _("Cannot open included file: %s. ERR=%s\n"),
+ p, strerror(errno));
+ goto bail_out;
+ }
+ /* Copy File options */
+ if (ie->fileopts) {
+ strcpy(buf, ie->fileopts->opts);
+ } else {
+ strcpy(buf, ie->opts);
+ }
+ strcat(buf, " ");
+ optlen = strlen(buf);
+ while (fgets(buf+optlen, sizeof(buf)-optlen, ffd)) {
+ fd->msglen = Mmsg(&fd->msg, "%s", buf);
+ if (!bnet_send(fd)) {
+ Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
+ goto bail_out;
+ }
+ }
+ fclose(ffd);
+ break;
+ default:
+ if (ie->fileopts) {
+ pm_strcpy(&fd->msg, ie->fileopts->opts);
+ Dmsg1(200, "Fileopts=%s\n", fd->msg);
+ } else {
+ pm_strcpy(&fd->msg, ie->opts);
+ }
+ pm_strcat(&fd->msg, " ");
+ pm_strcat(&fd->msg, ie->name_list[j]);
+ Dmsg1(200, "Include name=%s\n", fd->msg);
+ fd->msglen = strlen(fd->msg);
if (!bnet_send(fd)) {
Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
goto bail_out;
}
+ break;
}
- fclose(ffd);
- break;
- default:
- strcpy(fd->msg, ie->opts);
- pm_strcat(&fd->msg, ie->name);
- Dmsg1(000, "Include name=%s\n", ie->name);
- fd->msglen = strlen(fd->msg);
- if (!bnet_send(fd)) {
- Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
- goto bail_out;
- }
- break;
}
}
bnet_sig(fd, BNET_EOD); /* end of data */
{
FILESET *fileset;
BSOCK *fd;
- int i;
fd = jcr->file_bsock;
fileset = jcr->fileset;
fd->msglen = sprintf(fd->msg, exc);
bnet_send(fd);
- for (i=0; i < fileset->num_excludes; i++) {
- pm_strcpy(&fd->msg, fileset->exclude_array[i]->name);
- fd->msglen = strlen(fd->msg);
- Dmsg1(200, "dird>filed: exclude file: %s\n", fileset->exclude_array[i]->name);
- if (!bnet_send(fd)) {
- Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
- set_jcr_job_status(jcr, JS_ErrorTerminated);
- return 0;
+ for (int i=0; i < fileset->num_excludes; i++) {
+ INCEXE *ie;
+ ie = fileset->exclude_items[i];
+ for (int j=0; j<ie->num_names; j++) {
+ pm_strcpy(&fd->msg, ie->name_list[j]);
+ fd->msglen = strlen(fd->msg);
+ Dmsg1(200, "Exclude name: %s\n", fd->msg);
+ if (!bnet_send(fd)) {
+ Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
+ set_jcr_job_status(jcr, JS_ErrorTerminated);
+ return 0;
+ }
}
}
bnet_sig(fd, BNET_EOD);