]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/filed/restore.c
18Jun08
[bacula/bacula] / bacula / src / filed / restore.c
index 8abe454371995e1d14c639c641a800e3b63f3872..299b78f9e2a5b33902fbe92add40c289f14028d2 100644 (file)
@@ -120,7 +120,7 @@ bool flush_cipher(JCR *jcr, BFILE *bfd, uint64_t *addr, int flags,
 
 /*
  * Close a bfd check that we are at the expected file offset.
- * Makes some code in set_attributes().
+ * Makes use of some code from set_attributes().
  */
 static int bclose_chksize(JCR *jcr, BFILE *bfd, boffset_t osize)
 {
@@ -299,7 +299,11 @@ void do_restore(JCR *jcr)
                deallocate_fork_cipher(rctx);
             }
 
-            set_attributes(jcr, attr, &rctx.bfd);
+            if (jcr->plugin) {
+               plugin_set_attributes(jcr, attr, &rctx.bfd);
+            } else {
+               set_attributes(jcr, attr, &rctx.bfd);
+            }
             extract = false;
 
             /* Verify the cryptographic signature, if any */
@@ -316,6 +320,11 @@ void do_restore(JCR *jcr)
             bclose(&rctx.bfd);
          }
 
+         /* TODO: manage deleted files */
+         if (rctx.type == FT_DELETED) { /* deleted file */
+            continue;
+         }
+
          /*
           * Unpack attributes and do sanity check them
           */
@@ -345,11 +354,16 @@ void do_restore(JCR *jcr)
          build_attr_output_fnames(jcr, attr);
 
          /*
-          * Now determine if we are extracting or not.
+          * Try to actually create the file, which returns a status telling
+          *  us if we need to extract or not.
           */
          jcr->num_files_examined++;
          extract = false;
-         stat = create_file(jcr, attr, &rctx.bfd, jcr->replace);
+         if (jcr->plugin) {
+            stat = plugin_create_file(jcr, attr, &rctx.bfd, jcr->replace);
+         } else {
+            stat = create_file(jcr, attr, &rctx.bfd, jcr->replace);
+         }
          Dmsg2(30, "Outfile=%s create_file stat=%d\n", attr->ofname, stat);
          switch (stat) {
          case CF_ERROR:
@@ -376,7 +390,11 @@ void do_restore(JCR *jcr)
             }
             if (!extract) {
                /* set attributes now because file will not be extracted */
-               set_attributes(jcr, attr, &rctx.bfd);
+               if (jcr->plugin) {
+                  plugin_set_attributes(jcr, attr, &rctx.bfd);
+               } else {
+                  set_attributes(jcr, attr, &rctx.bfd);
+               }
             }
             break;
          }
@@ -631,6 +649,11 @@ void do_restore(JCR *jcr)
          }
          break;
 
+      case STREAM_PLUGIN_NAME:
+         Dmsg1(000, "restore stream_plugin_name=%s\n", sd->msg);
+         plugin_name_stream(jcr, sd->msg);
+         break;
+
       default:
          /* If extracting, wierd stream (not 1 or 2), close output file anyway */
          if (extract) {
@@ -642,7 +665,11 @@ void do_restore(JCR *jcr)
             deallocate_cipher(rctx);
             deallocate_fork_cipher(rctx);
 
-            set_attributes(jcr, attr, &rctx.bfd);
+            if (jcr->plugin) {
+               plugin_set_attributes(jcr, attr, &rctx.bfd);
+            } else {
+               set_attributes(jcr, attr, &rctx.bfd);
+            }
 
             /* Verify the cryptographic signature if any */
             rctx.type = attr->type;
@@ -671,7 +698,11 @@ void do_restore(JCR *jcr)
       deallocate_cipher(rctx);
       deallocate_fork_cipher(rctx);
 
-      set_attributes(jcr, attr, &rctx.bfd);
+      if (jcr->plugin) {
+         plugin_set_attributes(jcr, attr, &rctx.bfd);
+      } else {
+         set_attributes(jcr, attr, &rctx.bfd);
+      }
 
       /* Verify the cryptographic signature on the last file, if any */
       rctx.type = attr->type;
@@ -775,9 +806,8 @@ static const char *zlib_strerror(int stat)
 }
 #endif
 
-static int do_file_digest(FF_PKT *ff_pkt, void *pkt, bool top_level) 
+static int do_file_digest(JCR *jcr, FF_PKT *ff_pkt, bool top_level) 
 {
-   JCR *jcr = (JCR *)pkt;
    Dmsg1(50, "do_file_digest jcr=%p\n", jcr);
    return (digest_file(jcr, ff_pkt, jcr->crypto.digest));
 }
@@ -848,7 +878,7 @@ static bool verify_signature(JCR *jcr, r_ctx &rctx)
             /* Checksum the entire file */
             /* Make sure we don't modify JobBytes by saving and restoring it */
             saved_bytes = jcr->JobBytes;                     
-            if (find_one_file(jcr, jcr->ff, do_file_digest, jcr, jcr->last_fname, (dev_t)-1, 1) != 0) {
+            if (find_one_file(jcr, jcr->ff, do_file_digest, jcr->last_fname, (dev_t)-1, 1) != 0) {
                Jmsg(jcr, M_ERROR, 0, _("Digest one file failed for file: %s\n"), 
                     jcr->last_fname);
                jcr->JobBytes = saved_bytes;
@@ -1084,7 +1114,6 @@ int32_t extract_data(JCR *jcr, BFILE *bfd, POOLMEM *buf, int32_t buflen,
        * packet length may be re-read by unser_crypto_packet_len() */
       cipher_ctx->packet_len = 0;
    }
-
    return wsize;
 }