]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/filed/restore.c
Add const for Solaris' C++ compiler
[bacula/bacula] / bacula / src / filed / restore.c
index 8b4a7e0772d7e1c588326db94984ef6bfaa72fb0..6066677bdebb90494e2bb53d95b1bcc096abccf0 100644 (file)
@@ -33,6 +33,9 @@
 static char rec_header[] = "rechdr %ld %ld %ld %ld %ld";
 
 /* Forward referenced functions */
+#ifdef HAVE_LIBZ
+static const char *zlib_strerror(int stat);
+#endif
 
 #define RETRY 10                     /* retry wait time */
 
@@ -42,13 +45,12 @@ static char rec_header[] = "rechdr %ld %ld %ld %ld %ld";
  */
 void do_restore(JCR *jcr)
 {
-   int wherelen;
    BSOCK *sd;
    int32_t stream;
    uint32_t size;
    uint32_t VolSessionId, VolSessionTime;
    int32_t file_index;
-   int extract = FALSE;
+   bool extract = false;
    BFILE bfd;
    int stat;
    uint32_t total = 0;               /* Job total but only 32 bits for debug */
@@ -60,13 +62,21 @@ void do_restore(JCR *jcr)
    int prog_name_msg = 0;
    ATTR *attr;
    
-   wherelen = strlen(jcr->where);
 
    binit(&bfd);
    sd = jcr->store_bsock;
    set_jcr_job_status(jcr, JS_Running);
 
-   if (!bnet_set_buffer_size(sd, MAX_NETWORK_BUFFER_SIZE, BNET_SETBUF_READ)) {
+   LockRes();
+   CLIENT *client = (CLIENT *)GetNextRes(R_CLIENT, NULL);
+   UnlockRes();
+   uint32_t buf_size;
+   if (client) {
+      buf_size = client->max_network_buffer_size;
+   } else {
+      buf_size = 0;                  /* use default */
+   }
+   if (!bnet_set_buffer_size(sd, buf_size, BNET_SETBUF_WRITE)) {
       set_jcr_job_status(jcr, JS_ErrorTerminated);
       return;
    }
@@ -117,7 +127,6 @@ void do_restore(JCR *jcr)
       switch (stream) {
       case STREAM_UNIX_ATTRIBUTES:
       case STREAM_UNIX_ATTRIBUTES_EX:
-        uint32_t LinkFI;
 
          Dmsg1(30, "Stream=Unix Attributes. extract=%d\n", extract);
         /* If extracting, it was from previous stream, so
@@ -128,7 +137,7 @@ void do_restore(JCR *jcr)
                Jmsg0(jcr, M_ERROR, 0, _("Logic error output file should be open\n"));
            }
            set_attributes(jcr, attr, &bfd);
-           extract = FALSE;
+           extract = false;
             Dmsg0(30, "Stop extracting.\n");
         }
 
@@ -145,21 +154,29 @@ void do_restore(JCR *jcr)
          Dmsg3(200, "File %s\nattrib=%s\nattribsEx=%s\n", attr->fname, 
               attr->attr, attr->attrEx);
 
-        decode_stat(attr->attr, &attr->statp, &LinkFI);
+        attr->data_stream = decode_stat(attr->attr, &attr->statp, &attr->LinkFI);
+
+        if (!is_stream_supported(attr->data_stream)) {
+           if (!non_support_data++) {
+               Jmsg(jcr, M_ERROR, 0, _("%s stream not supported on this Client.\n"),
+                 stream_to_ascii(attr->data_stream));
+           }
+           continue;
+        }
 
         build_attr_output_fnames(jcr, attr);
 
         jcr->num_files_examined++;
 
          Dmsg1(30, "Outfile=%s\n", attr->ofname);
-        extract = FALSE;
+        extract = false;
         stat = create_file(jcr, attr, &bfd, jcr->replace);
         switch (stat) {
         case CF_ERROR:
         case CF_SKIP:
            break;
         case CF_EXTRACT:
-           extract = TRUE;
+           extract = true;
            P(jcr->mutex);
            pm_strcpy(&jcr->last_fname, attr->ofname);
            V(jcr->mutex);
@@ -181,23 +198,11 @@ void do_restore(JCR *jcr)
         }  
         break;
 
-      /* Windows Backup data stream */
-      case STREAM_WIN32_DATA:  
-        if (!is_win32_backup()) {
-           if (!non_support_data) {
-               Jmsg(jcr, M_ERROR, 0, _("Win32 backup data not supported on this Client.\n"));
-           }
-           extract = FALSE;
-           non_support_data++;
-           continue;
-        }
-        goto extract_data;
-
       /* Data stream */
       case STREAM_FILE_DATA:
       case STREAM_SPARSE_DATA: 
+      case STREAM_WIN32_DATA:  
 
-extract_data:
         if (extract) {
            if (stream == STREAM_SPARSE_DATA) {
               ser_declare;
@@ -213,7 +218,8 @@ extract_data:
                  if (blseek(&bfd, (off_t)fileAddr, SEEK_SET) < 0) {
                      Jmsg3(jcr, M_ERROR, 0, _("Seek to %s error on %s: ERR=%s\n"),
                         edit_uint64(fileAddr, ec1), attr->ofname, berror(&bfd));
-                    extract = FALSE;
+                    extract = false;
+                    bclose(&bfd);
                     continue;
                  }
               }
@@ -225,7 +231,8 @@ extract_data:
            if ((uint32_t)bwrite(&bfd, wbuf, wsize) != wsize) {
                Dmsg0(0, "===Write error===\n");
                Jmsg2(jcr, M_ERROR, 0, _("Write error on %s: ERR=%s\n"), attr->ofname, berror(&bfd));
-              extract = FALSE;
+              extract = false;
+              bclose(&bfd);
               continue;
            } 
            total += wsize;
@@ -235,30 +242,19 @@ extract_data:
         }
         break;
 
-      /* Windows Backup GZIP data stream */
-      case STREAM_WIN32_GZIP_DATA:  
-        if (!is_win32_backup()) {
-           if (!non_support_attr) {
-               Jmsg(jcr, M_ERROR, 0, _("Win32 GZIP backup data not supported on this Client.\n"));
-           }
-           extract = FALSE;
-           non_support_attr++;
-           continue;
-        }
-        /* Fall through desired */
-
       /* GZIP data stream */
       case STREAM_GZIP_DATA:
       case STREAM_SPARSE_GZIP_DATA:  
+      case STREAM_WIN32_GZIP_DATA:  
 #ifdef HAVE_LIBZ
         if (extract) {
-           ser_declare;
            uLong compress_len;
-           uint64_t faddr;
-           char ec1[50];
            int stat;
 
            if (stream == STREAM_SPARSE_GZIP_DATA) {
+              ser_declare;
+              uint64_t faddr;
+              char ec1[50];
               wbuf = sd->msg + SPARSE_FADDR_SIZE;
               wsize = sd->msglen - SPARSE_FADDR_SIZE;
               ser_begin(sd->msg, SPARSE_FADDR_SIZE);
@@ -268,7 +264,8 @@ extract_data:
                  if (blseek(&bfd, (off_t)fileAddr, SEEK_SET) < 0) {
                      Jmsg3(jcr, M_ERROR, 0, _("Seek to %s error on %s: ERR=%s\n"),
                         edit_uint64(fileAddr, ec1), attr->ofname, berror(&bfd));
-                    extract = FALSE;
+                    extract = false;
+                    bclose(&bfd);
                     continue;
                  }
               }
@@ -280,8 +277,10 @@ extract_data:
             Dmsg2(100, "Comp_len=%d msglen=%d\n", compress_len, wsize);
            if ((stat=uncompress((Byte *)jcr->compress_buf, &compress_len, 
                  (const Byte *)wbuf, (uLong)wsize)) != Z_OK) {
-               Jmsg(jcr, M_ERROR, 0, _("Uncompression error. ERR=%d\n"), stat);
-              extract = FALSE;
+               Jmsg(jcr, M_ERROR, 0, _("Uncompression error on file %s. ERR=%s\n"), 
+                 attr->ofname, zlib_strerror(stat));
+              extract = false;
+              bclose(&bfd);
               continue;
            }
 
@@ -289,7 +288,8 @@ extract_data:
            if ((uLong)bwrite(&bfd, jcr->compress_buf, compress_len) != compress_len) {
                Dmsg0(0, "===Write error===\n");
                Jmsg2(jcr, M_ERROR, 0, _("Write error on %s: %s\n"), attr->ofname, berror(&bfd));
-              extract = FALSE;
+              extract = false;
+              bclose(&bfd);
               continue;
            }
            total += compress_len;
@@ -300,7 +300,8 @@ extract_data:
 #else
         if (extract) {
             Jmsg(jcr, M_ERROR, 0, _("GZIP data stream found, but GZIP not configured!\n"));
-           extract = FALSE;
+           extract = false;
+           bclose(&bfd);
            continue;
         }
 #endif
@@ -326,7 +327,7 @@ extract_data:
                Jmsg0(jcr, M_ERROR, 0, _("Logic error output file should be open but is not.\n"));
            }
            set_attributes(jcr, attr, &bfd);
-           extract = FALSE;
+           extract = false;
         }
          Jmsg(jcr, M_ERROR, 0, _("Unknown stream=%d ignored. This shouldn't happen!\n"), stream);
          Dmsg2(0, "None of above!!! stream=%d data=%s\n", stream,sd->msg);
@@ -351,6 +352,7 @@ ok_out:
       free(jcr->compress_buf);
       jcr->compress_buf = NULL;
    }
+   bclose(&bfd);
    free_attr(attr);
    Dmsg2(10, "End Do Restore. Files=%d Bytes=%" lld "\n", jcr->JobFiles,
       jcr->JobBytes);
@@ -359,3 +361,31 @@ ok_out:
         non_support_data, non_support_attr);
    }
 }         
+
+#ifdef HAVE_LIBZ
+/*
+ * Convert ZLIB error code into an ASCII message
+ */
+static const char *zlib_strerror(int stat)
+{
+   if (stat >= 0) {
+      return "None";
+   }
+   switch (stat) {
+   case Z_ERRNO:
+      return "Zlib errno";
+   case Z_STREAM_ERROR:
+      return "Zlib stream error";
+   case Z_DATA_ERROR:
+      return "Zlib data error";
+   case Z_MEM_ERROR:
+      return "Zlib memory error";
+   case Z_BUF_ERROR:
+      return "Zlib buffer error";
+   case Z_VERSION_ERROR:
+      return "Zlib version error";
+   default:
+      return "*none*";
+   }
+}
+#endif