From: Eric Bollengier Date: Fri, 5 Nov 2010 17:52:36 +0000 (+0100) Subject: Permit to get Where/RegexWhere from Plugin and give access to Accurate data X-Git-Tag: Release-7.0.0~1437 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=df361c105e153ec361c3eb79025f39124b0c66fa;p=bacula%2Fbacula Permit to get Where/RegexWhere from Plugin and give access to Accurate data --- diff --git a/bacula/src/filed/fd_plugins.c b/bacula/src/filed/fd_plugins.c index cc31de09b6..44f9be503d 100644 --- a/bacula/src/filed/fd_plugins.c +++ b/bacula/src/filed/fd_plugins.c @@ -44,6 +44,7 @@ const char *plugin_type = "-fd.so"; #endif extern int save_file(JCR *jcr, FF_PKT *ff_pkt, bool top_level); +extern bool check_changes(JCR *jcr, FF_PKT *ff_pkt); /* Function pointers to be set here */ extern DLL_IMP_EXP int (*plugin_bopen)(BFILE *bfd, const char *fname, int flags, mode_t mode); @@ -73,6 +74,7 @@ static bRC baculaNewOptions(bpContext *ctx); static bRC baculaNewInclude(bpContext *ctx); static bool is_plugin_compatible(Plugin *plugin); static bool get_plugin_name(JCR *jcr, char *cmd, int *ret); +static bRC baculaCheckChanges(bpContext *ctx, struct save_pkt *sp); /* * These will be plugged into the global pointer structure for @@ -108,7 +110,8 @@ static bFuncs bfuncs = { baculaAddRegex, baculaAddWild, baculaNewOptions, - baculaNewInclude + baculaNewInclude, + baculaCheckChanges }; /* @@ -1014,6 +1017,12 @@ static bRC baculaGetValue(bpContext *ctx, bVariable var, void *value) case bVarWorkingDir: *(void **)value = me->working_directory; break; + case bVarWhere: + *(char **)value = jcr->where; + break; + case bVarRegexWhere: + *(char **)value = jcr->RegexWhere; + break; } return bRC_OK; } @@ -1243,6 +1252,50 @@ static bRC baculaNewInclude(bpContext *ctx) } +/* + * Check if a file have to be backuped using Accurate code + */ +static bRC baculaCheckChanges(bpContext *ctx, struct save_pkt *sp) +{ + JCR *jcr; + bacula_ctx *bctx; + FF_PKT *ff_pkt; + bRC ret = bRC_Error; + + if (!is_ctx_good(ctx, jcr, bctx)) { + goto bail_out; + } + if (!sp) { + goto bail_out; + } + + ff_pkt = jcr->ff; + /* + * Copy fname and link because save_file() zaps them. This + * avoids zaping the plugin's strings. + */ + ff_pkt->type = sp->type; + if (!sp->fname) { + Jmsg0(jcr, M_FATAL, 0, _("Command plugin: no fname in baculaCheckChanges packet.\n")); + goto bail_out; + } + + ff_pkt->fname = sp->fname; + ff_pkt->link = sp->link; + memcpy(&ff_pkt->statp, &sp->statp, sizeof(ff_pkt->statp)); + + if (check_changes(jcr, ff_pkt)) { + ret = bRC_OK; + } else { + ret = bRC_Seen; + } + +bail_out: + Dmsg1(100, "checkChanges=%i\n", ret); + return ret; +} + + #ifdef TEST_PROGRAM int (*plugin_bopen)(JCR *jcr, const char *fname, int flags, mode_t mode) = NULL; diff --git a/bacula/src/filed/fd_plugins.h b/bacula/src/filed/fd_plugins.h index 8ff6b44ff0..8fd4c6275d 100644 --- a/bacula/src/filed/fd_plugins.h +++ b/bacula/src/filed/fd_plugins.h @@ -175,7 +175,9 @@ typedef enum { bVarFileSeen = 10, bVarVssObject = 11, bVarVssDllHandle = 12, - bVarWorkingDir = 13 + bVarWorkingDir = 13, + bVarWhere = 14, + bVarRegexWhere = 15 } bVariable; /* Events that are passed to plugin */ @@ -254,6 +256,7 @@ typedef struct s_baculaFuncs { bRC (*AddWild)(bpContext *ctx, const char *item, int type); bRC (*NewOptions)(bpContext *ctx); bRC (*NewInclude)(bpContext *ctx); + bRC (*checkChanges)(bpContext *ctx, struct save_pkt *sp); } bFuncs; @@ -272,7 +275,7 @@ typedef enum { #define FD_PLUGIN_MAGIC "*FDPluginData*" -#define FD_PLUGIN_INTERFACE_VERSION 4 +#define FD_PLUGIN_INTERFACE_VERSION 5 typedef struct s_pluginInfo { uint32_t size; diff --git a/bacula/src/findlib/find_one.c b/bacula/src/findlib/find_one.c index 1d8313f029..6cad341518 100644 --- a/bacula/src/findlib/find_one.c +++ b/bacula/src/findlib/find_one.c @@ -274,7 +274,7 @@ bool has_file_changed(JCR *jcr, FF_PKT *ff_pkt) * For incremental/diffential or accurate backups, we * determine if the current file has changed. */ -static bool check_changes(JCR *jcr, FF_PKT *ff_pkt) +bool check_changes(JCR *jcr, FF_PKT *ff_pkt) { /* in special mode (like accurate backup), the programmer can * choose his comparison function. diff --git a/bacula/src/findlib/protos.h b/bacula/src/findlib/protos.h index a272a15e60..71076c6b9d 100644 --- a/bacula/src/findlib/protos.h +++ b/bacula/src/findlib/protos.h @@ -69,6 +69,7 @@ int find_one_file(JCR *jcr, FF_PKT *ff, char *p, dev_t parent_device, bool top_level); int term_find_one(FF_PKT *ff); bool has_file_changed(JCR *jcr, FF_PKT *ff_pkt); +bool check_changes(JCR *jcr, FF_PKT *ff_pkt); /* From get_priv.c */ int enable_backup_privileges(JCR *jcr, int ignore_errors);