From 33e4aa117dc4abde2546a75eb6d845e7fdc2904d Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Mon, 31 Aug 2009 14:57:38 +0200 Subject: [PATCH] Use new db_list_ctx class instead of bad POOLMEM* --- bacula/src/cats/protos.h | 2 +- bacula/src/cats/sql_get.c | 4 ++-- bacula/src/dird/backup.c | 25 +++++++++++++------------ bacula/src/dird/ua_restore.c | 9 +++++---- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/bacula/src/cats/protos.h b/bacula/src/cats/protos.h index 2b063f69c4..a6ba803fb9 100644 --- a/bacula/src/cats/protos.h +++ b/bacula/src/cats/protos.h @@ -147,7 +147,7 @@ void db_make_inchanger_unique(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr); int db_update_stats(JCR *jcr, B_DB *mdb, utime_t age); -bool db_get_used_base_jobids(JCR *jcr, B_DB *mdb, POOLMEM *jobids, POOLMEM *result); +bool db_get_used_base_jobids(JCR *jcr, B_DB *mdb, POOLMEM *jobids, db_list_ctx *result); bool db_create_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar); bool db_create_base_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar); bool db_commit_base_file_attributes_record(JCR *jcr, B_DB *mdb); diff --git a/bacula/src/cats/sql_get.c b/bacula/src/cats/sql_get.c index 447bd489e2..2172169661 100644 --- a/bacula/src/cats/sql_get.c +++ b/bacula/src/cats/sql_get.c @@ -1101,7 +1101,7 @@ bool db_get_file_list(JCR *jcr, B_DB *mdb, char *jobids, * This procedure gets the base jobid list used by jobids, * You can specify jobids == result to concat base jobids to current jobids */ -bool db_get_used_base_jobids(JCR *jcr, B_DB *mdb, POOLMEM *jobids, POOLMEM *result) +bool db_get_used_base_jobids(JCR *jcr, B_DB *mdb, POOLMEM *jobids, db_list_ctx *result) { POOL_MEM buf; Mmsg(buf, @@ -1109,7 +1109,7 @@ bool db_get_used_base_jobids(JCR *jcr, B_DB *mdb, POOLMEM *jobids, POOLMEM *resu " FROM Job JOIN BaseFiles USING (JobId) " " WHERE Job.HasBase = 1 " " AND JobId IN (%s) ", jobids); - return db_sql_query(mdb, buf.c_str(), db_get_int_handler, result); + return db_sql_query(mdb, buf.c_str(), db_list_handler, result); } /* The decision do change an incr/diff was done before diff --git a/bacula/src/dird/backup.c b/bacula/src/dird/backup.c index dd7d1fc59d..30e1cd1e55 100644 --- a/bacula/src/dird/backup.c +++ b/bacula/src/dird/backup.c @@ -106,7 +106,7 @@ bool do_backup_init(JCR *jcr) /* Take all base jobs from job resource and find the * last L_BASE jobid. */ -static bool get_base_jobids(JCR *jcr, POOLMEM *jobids) +static bool get_base_jobids(JCR *jcr, db_list_ctx *jobids) { JOB_DBR jr; JOB *job; @@ -125,14 +125,15 @@ static bool get_base_jobids(JCR *jcr, POOLMEM *jobids) db_get_base_jobid(jcr, jcr->db, &jr, &id); if (id) { - if (jobids[0]) { - pm_strcat(jobids, ","); + if (jobids->count) { + pm_strcat(jobids->list, ","); } - pm_strcat(jobids, edit_uint64(id, str_jobid)); + pm_strcat(jobids->list, edit_uint64(id, str_jobid)); + jobids->count++; } } - return *jobids != '\0'; + return jobids->count > 0; } /* @@ -186,18 +187,18 @@ bool send_accurate_current_files(JCR *jcr) if (jcr->get_JobLevel() == L_FULL) { /* On Full mode, if no previous base job, no accurate things */ - if (!get_base_jobids(jcr, jobids)) { + if (!get_base_jobids(jcr, &jobids)) { goto bail_out; } jcr->HasBase = true; - Jmsg(jcr, M_INFO, 0, _("Using BaseJobId(s): %s\n"), jobids); + Jmsg(jcr, M_INFO, 0, _("Using BaseJobId(s): %s\n"), jobids.list); } else { /* For Incr/Diff level, we search for older jobs */ - db_accurate_get_jobids(jcr, jcr->db, &jcr->jr, jobids); + db_accurate_get_jobids(jcr, jcr->db, &jcr->jr, &jobids); /* We are in Incr/Diff, but no Full to build the accurate list... */ - if (*jobids == 0) { + if (jobids.count == 0) { ret=false; Jmsg(jcr, M_FATAL, 0, _("Cannot find previous jobids.\n")); goto bail_out; @@ -220,13 +221,13 @@ bool send_accurate_current_files(JCR *jcr) } if (jcr->HasBase) { - jcr->nb_base_files = str_to_int64(nb); - db_create_base_file_list(jcr, jcr->db, jobids); + jcr->nb_base_files = str_to_int64(nb.list); + db_create_base_file_list(jcr, jcr->db, jobids.list); db_get_base_file_list(jcr, jcr->db, accurate_list_handler, (void *)jcr); } else { - db_get_file_list(jcr, jcr->db_batch, jobids, + db_get_file_list(jcr, jcr->db_batch, jobids.list, accurate_list_handler, (void *)jcr); } diff --git a/bacula/src/dird/ua_restore.c b/bacula/src/dird/ua_restore.c index 0e8a09d17c..477025fbf2 100644 --- a/bacula/src/dird/ua_restore.c +++ b/bacula/src/dird/ua_restore.c @@ -310,18 +310,19 @@ bail_out: */ static void get_and_display_basejobs(UAContext *ua, RESTORE_CTX *rx) { - rx->BaseJobIds[0] = '\0'; + db_list_ctx jobids; - if (!db_get_used_base_jobids(ua->jcr, ua->db, rx->JobIds, rx->BaseJobIds)) { + if (!db_get_used_base_jobids(ua->jcr, ua->db, rx->JobIds, &jobids)) { ua->warning_msg("%s", db_strerror(ua->db)); } - if (*rx->BaseJobIds) { + if (jobids.count) { POOL_MEM q; - Mmsg(q, uar_print_jobs, rx->BaseJobIds); + Mmsg(q, uar_print_jobs, jobids.list); ua->send_msg(_("The restore will use the following job(s) as Base\n")); db_list_sql_query(ua->jcr, ua->db, q.c_str(), prtit, ua, 1, HORZ_LIST); } + pm_strcpy(rx->BaseJobIds, jobids.list); } static void free_rx(RESTORE_CTX *rx) -- 2.39.5