]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Change plugin object-related logic in bscan to avoid duplicates
authorMichal Rakowski <michal.rakowski@baculasystems.com>
Tue, 1 Dec 2020 12:33:11 +0000 (13:33 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:02:59 +0000 (09:02 +0100)
bacula/src/stored/bscan.c

index 48239bcb14426e3bfbf950a0507073d467d2d6ef..3341a71efd4ef0664c9085ad921b3a289f45d7cd 100644 (file)
@@ -811,23 +811,22 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec)
             break;
          }
 
-         obj_r.JobId = mjcr->JobId;
-
-         /* Look if we have already the same object */
-         if (db_get_plugin_object_record(mjcr, db, &obj_r)) {
-            if (verbose) {
-               Pmsg1(0, _("PLUGIN_OBJECT: Found Plugin Object (id: %lu) in the catalog\n"), obj_r.ObjectId);
-            }
-         } else if (update_db) {
-            /* Send it */
-            Pmsg1(0, _("PLUGIN_OBJECT: Inserting Plugin Object (ObjectName: %s) into the catalog\n"), obj_r.ObjectName);
-            if (!db_create_object_record(mjcr, db, &obj_r)) {
-               Jmsg1(mjcr, M_FATAL, 0, _("Plugin object create error. %s"), db_strerror(db));
+         if (mjcr->bscan_created) {
+            // bscan created this job record so we need to recreate objects as well
+            if (update_db) {
+               /* Send it */
+               Pmsg1(0, _("PLUGIN_OBJECT: Inserting Plugin Object (ObjectName: %s) into the catalog\n"), obj_r.ObjectName);
+               obj_r.JobId = mjcr->JobId;
+               // Create record with updated jobid
+               if (!db_create_object_record(mjcr, db, &obj_r)) {
+                  Jmsg1(mjcr, M_FATAL, 0, _("Plugin object create error. %s"), db_strerror(db));
+               }
             }
          } else {
             Pmsg1(0, _("PLUGIN_OBJECT: Found Plugin Object (ObjectName: %s) on the volume\n"), obj_r.ObjectName);
          }
 
+         mjcr->dec_use_count(); /* Decrease reference counter increased by get_jcr_by_session call */
          break;
       }