]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/filed/restore.c
More cleanup
[bacula/bacula] / bacula / src / filed / restore.c
index 5bac82fd5204a2550422d1f70f3d04fee46b808e..f5d06e33258dc42134c95bf6d931845c032c15a4 100644 (file)
@@ -7,7 +7,7 @@
  *
  */
 /*
-   Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
+   Copyright (C) 2000-2003 Kern Sibbald and John Walker
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -56,7 +56,7 @@ void do_restore(JCR *jcr)
    struct stat statp;
    int extract = FALSE;
    int ofd = -1;
-   int type;
+   int type, stat;
    uint32_t total = 0;               /* Job total but only 32 bits for debug */
    char *wbuf;                       /* write buffer */
    uint32_t wsize;                   /* write size */
@@ -65,9 +65,10 @@ void do_restore(JCR *jcr)
    wherelen = strlen(jcr->where);
 
    sd = jcr->store_bsock;
-   jcr->JobStatus = JS_Running;
+   set_jcr_job_status(jcr, JS_Running);
 
    if (!bnet_set_buffer_size(sd, MAX_NETWORK_BUFFER_SIZE, BNET_SETBUF_READ)) {
+      set_jcr_job_status(jcr, JS_ErrorTerminated);
       return;
    }
    jcr->buf_size = sd->msglen;
@@ -106,8 +107,9 @@ void do_restore(JCR *jcr)
       /* 
        * Now we expect the Stream Data
        */
-      if (bnet_recv(sd) < 0 && !job_cancelled(jcr)) {
+      if (bnet_recv(sd) < 0) {
          Jmsg1(jcr, M_FATAL, 0, _("Data record error. ERR=%s\n"), bnet_strerror(sd));
+        goto bail_out;
       }
       if (size != (uint32_t)sd->msglen) {
          Jmsg2(jcr, M_FATAL, 0, _("Actual data size %d not same as header %d\n"), sd->msglen, size);
@@ -125,7 +127,7 @@ void do_restore(JCR *jcr)
          */
         if (extract) {
            if (ofd < 0) {
-               Emsg0(M_ERROR, 0, _("Logic error output file should be open\n"));
+               Jmsg0(jcr, M_ERROR, 0, _("Logic error output file should be open\n"));
            }
            set_attributes(jcr, fname, ofile, lname, type, stream, 
                           &statp, attribsEx, &ofd);
@@ -245,15 +247,27 @@ void do_restore(JCR *jcr)
         }
 
          Dmsg1(30, "Outfile=%s\n", ofile);
-        print_ls_output(jcr, ofile, lname, type, &statp);
 
-        extract = create_file(jcr, fname, ofile, lname, type, 
-                              stream, &statp, attribsEx, &ofd);
-         Dmsg1(40, "Extract=%d\n", extract);
-        if (extract) {
+        extract = FALSE;
+        stat = create_file(jcr, fname, ofile, lname, type, 
+                           stream, &statp, attribsEx, &ofd, jcr->replace);
+        switch (stat) {
+        case CF_ERROR:
+        case CF_SKIP:
+           break;
+        case CF_EXTRACT:
+           extract = TRUE;
+           P(jcr->mutex);
+           pm_strcpy(&jcr->last_fname, ofile);
+           V(jcr->mutex);
+           /* Fall-through wanted */
+        case CF_CREATED:
            jcr->JobFiles++;
            fileAddr = 0;
-        }
+           print_ls_output(jcr, ofile, lname, type, &statp);
+           break;
+        }  
+
         jcr->num_files_examined++;
 
       /* Data stream */
@@ -295,16 +309,22 @@ void do_restore(JCR *jcr)
       } else if (stream == STREAM_GZIP_DATA || stream == STREAM_SPARSE_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) {
               wbuf = sd->msg + SPARSE_FADDR_SIZE;
               wsize = sd->msglen - SPARSE_FADDR_SIZE;
-              if (fileAddr != *((uint64_t *)sd->msg)) {
-                 fileAddr = *((uint64_t *)sd->msg);
+              ser_begin(sd->msg, SPARSE_FADDR_SIZE);
+              unser_uint64(faddr);
+              if (fileAddr != faddr) {
+                 fileAddr = faddr;
                  if (lseek(ofd, (off_t)fileAddr, SEEK_SET) < 0) {
-                     Jmsg2(jcr, M_ERROR, 0, "Seek error on %s: %s\n", ofile, strerror(errno));
+                     Jmsg3(jcr, M_ERROR, 0, _("Seek to %s error on %s: ERR=%s\n"),
+                        edit_uint64(fileAddr, ec1), ofile, strerror(errno));
                     goto bail_out;
                  }
               }
@@ -340,7 +360,7 @@ void do_restore(JCR *jcr)
       } else if (extract) {
          Dmsg1(30, "Found wierd stream %d\n", stream);
         if (ofd < 0) {
-            Emsg0(M_ERROR, 0, _("Logic error output file should be open\n"));
+            Jmsg0(jcr, M_ERROR, 0, _("Logic error output file should be open\n"));
         }
         set_attributes(jcr, fname, ofile, lname, type, stream, 
                        &statp, attribsEx, &ofd);
@@ -357,11 +377,11 @@ void do_restore(JCR *jcr)
       set_attributes(jcr, fname, ofile, lname, type, stream, 
                     &statp, attribsEx, &ofd);
    }
-   jcr->JobStatus = JS_Terminated;
+   set_jcr_job_status(jcr, JS_Terminated);
    goto ok_out;
 
 bail_out:
-   jcr->JobStatus = JS_ErrorTerminated;
+   set_jcr_job_status(jcr, JS_ErrorTerminated);
 ok_out:
    if (jcr->compress_buf) {
       free(jcr->compress_buf);
@@ -398,19 +418,21 @@ static void print_ls_output(JCR *jcr, char *fname, char *lname, int type, struct
    p = encode_time(statp->st_ctime, p);
    *p++ = ' ';
    *p++ = ' ';
-   for (f=fname; *f && (p-buf) < (int)sizeof(buf); )
+   for (f=fname; *f && (p-buf) < (int)sizeof(buf)-10; ) {
       *p++ = *f++;
+   }
    if (type == FT_LNK) {
       *p++ = ' ';
       *p++ = '-';
       *p++ = '>';
       *p++ = ' ';
       /* Copy link name */
-      for (f=lname; *f && (p-buf) < (int)sizeof(buf); )
+      for (f=lname; *f && (p-buf) < (int)sizeof(buf)-10; ) {
         *p++ = *f++;
+      }
    }
    *p++ = '\n';
    *p = 0;
    Dmsg0(20, buf);
-   Jmsg(jcr, M_INFO, 0, buf);
+   Jmsg(jcr, M_INFO, 0, "%s", buf);
 }