From: Kern Sibbald Date: Mon, 30 Aug 2010 20:35:59 +0000 (+0200) Subject: Make RestoreObject compatible with older FDs X-Git-Tag: Release-5.2.1~952 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=24b7b06e9065263b65ab5567093fd1ddea54cf8c;p=bacula%2Fbacula Make RestoreObject compatible with older FDs --- diff --git a/bacula/src/dird/fd_cmds.c b/bacula/src/dird/fd_cmds.c index 6c51d03833..64f12ef985 100644 --- a/bacula/src/dird/fd_cmds.c +++ b/bacula/src/dird/fd_cmds.c @@ -668,9 +668,15 @@ bail_out: return 0; } +struct OBJ_CTX { + JCR *jcr; + int count; +}; + static int restore_object_handler(void *ctx, int num_fields, char **row) { - JCR *jcr = (JCR *)ctx; + OBJ_CTX *octx = (OBJ_CTX *)ctx; + JCR *jcr = octx->jcr; BSOCK *fd; fd = jcr->file_bsock; @@ -704,6 +710,7 @@ static int restore_object_handler(void *ctx, int num_fields, char **row) str_to_uint64(row[1]), /* Object length */ &fd->msg, &fd->msglen); fd->send(); /* send object */ + octx->count++; if (debug_level) { for (int i=0; i < fd->msglen; i++) @@ -719,11 +726,13 @@ bool send_restore_objects(JCR *jcr) { POOL_MEM query(PM_MESSAGE); BSOCK *fd; + OBJ_CTX octx; -// Dmsg0(000, "Enter send_restore_objects\n"); if (!jcr->JobIds || !jcr->JobIds[0]) { return true; } + octx.jcr = jcr; + octx.count = 0; Mmsg(query, "SELECT JobId,ObjectLength,ObjectFullLength,ObjectIndex," "ObjectType,ObjectCompression,FileIndex,ObjectName," "RestoreObject " @@ -732,15 +741,20 @@ bool send_restore_objects(JCR *jcr) "ORDER BY ObjectIndex ASC", jcr->JobIds); /* restore_object_handler is called for each file found */ - db_sql_query(jcr->db, query.c_str(), restore_object_handler, (void *)jcr); -// Dmsg0(000, "All restore objects sent, looking for OKRestoreObject\n"); - fd = jcr->file_bsock; - fd->fsend("restoreobject end\n"); - if (!response(jcr, fd, OKRestoreObject, "RestoreObject", DISPLAY_ERROR)) { - Jmsg(jcr, M_FATAL, 0, _("RestoreObject failed.\n")); - return false; + db_sql_query(jcr->db, query.c_str(), restore_object_handler, (void *)&octx); + + /* + * Send to FD only if we have at least one restore object. + * This permits backward compatibility with older FDs. + */ + if (octx.count > 0) { + fd = jcr->file_bsock; + fd->fsend("restoreobject end\n"); + if (!response(jcr, fd, OKRestoreObject, "RestoreObject", DISPLAY_ERROR)) { + Jmsg(jcr, M_FATAL, 0, _("RestoreObject failed.\n")); + return false; + } } -// Dmsg0(000, "got for OKRestoreObject\n"); return true; }