]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/attr.c
First cut of bat rerun a Job from Jobs Run
[bacula/bacula] / bacula / src / lib / attr.c
index d3f59bffb041b8ee24afca39f6c529a93a4e6752..5cfb538b6f7056210163b4d93156d0111e712779 100644 (file)
@@ -1,19 +1,12 @@
-/*
- *   attr.c  Unpack an Attribute record returned from the tape
- *
- *    Kern Sibbald, June MMIII  (code pulled from filed/restore.c and updated)
- *
- *   Version $Id$
- */
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2003-2006 Free Software Foundation Europe e.V.
+   Copyright (C) 2003-2010 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    This program is Free Software; you can redistribute it and/or
-   modify it under the terms of version two of the GNU General Public
+   modify it under the terms of version three of the GNU Affero General Public
    License as published by the Free Software Foundation and included
    in the file LICENSE.
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.
 
-   You should have received a copy of the GNU General Public License
+   You should have received a copy of the GNU Affero General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Bacula® is a registered trademark of John Walker.
+   Bacula® is a registered trademark of Kern Sibbald.
    The licensor of Bacula is the Free Software Foundation Europe
    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
    Switzerland, email:ftf@fsfeurope.org.
 */
+/*
+ *   attr.c  Unpack an Attribute record returned from the tape
+ *
+ *    Kern Sibbald, June MMIII  (code pulled from filed/restore.c and updated)
+ *
+ */
+
 
 #include "bacula.h"
 #include "jcr.h"
 #include "lib/breg.h"
 
-ATTR *new_attr()
+static const int dbglvl = 150;
+
+ATTR *new_attr(JCR *jcr)
 {
    ATTR *attr = (ATTR *)malloc(sizeof(ATTR));
    memset(attr, 0, sizeof(ATTR));
    attr->ofname = get_pool_memory(PM_FNAME);
    attr->olname = get_pool_memory(PM_FNAME);
    attr->attrEx = get_pool_memory(PM_FNAME);
+   attr->jcr = jcr;
+   attr->uid = getuid();
    return attr;
 }
 
@@ -55,9 +59,10 @@ void free_attr(ATTR *attr)
    free(attr);
 }
 
-int unpack_attributes_record(JCR *jcr, int32_t stream, char *rec, ATTR *attr)
+int unpack_attributes_record(JCR *jcr, int32_t stream, char *rec, int32_t reclen, ATTR *attr)
 {
    char *p;
+   int object_len;
    /*
     * An Attributes record consists of:
     *    File_index
@@ -71,13 +76,13 @@ int unpack_attributes_record(JCR *jcr, int32_t stream, char *rec, ATTR *attr)
     *
     */
    attr->stream = stream;
-   Dmsg1(400, "Attr: %s\n", rec);
-   if (sscanf(rec, "%ld %ld", &attr->file_index, &attr->type) != 2) {
+   Dmsg1(dbglvl, "Attr: %s\n", rec);
+   if (sscanf(rec, "%d %d", &attr->file_index, &attr->type) != 2) {
       Jmsg(jcr, M_FATAL, 0, _("Error scanning attributes: %s\n"), rec);
-      Dmsg1(100, "\nError scanning attributes. %s\n", rec);
+      Dmsg1(dbglvl, "\nError scanning attributes. %s\n", rec);
       return 0;
    }
-   Dmsg2(400, "Got Attr: FilInx=%d type=%d\n", attr->file_index, attr->type);
+   Dmsg2(dbglvl, "Got Attr: FilInx=%d type=%d\n", attr->file_index, attr->type);
    if (attr->type & AR_DATA_STREAM) {
       attr->data_stream = 1;
    } else {
@@ -99,16 +104,25 @@ int unpack_attributes_record(JCR *jcr, int32_t stream, char *rec, ATTR *attr)
    attr->lname = p;                   /* set link position */
    while (*p++ != 0)                  /* skip link */
       { }
-   pm_strcpy(attr->attrEx, p);        /* copy extended attributes, if any */
-
-   if (attr->data_stream) {
-      int64_t val;
-      while (*p++ != 0)               /* skip extended attributes */
-         { }
-      from_base64(&val, p);
-      attr->data_stream = (int32_t)val;
+   if (attr->type == FT_RESTORE_FIRST) {
+      /* We have an object, so do a binary copy */
+      object_len = reclen + rec - p;
+      attr->attrEx = check_pool_memory_size(attr->attrEx, object_len + 1);
+      memcpy(attr->attrEx, p, object_len);  
+      /* Add a EOS for those who attempt to print the object */
+      p = attr->attrEx + object_len;
+      *p = 0;
+   } else {
+      pm_strcpy(attr->attrEx, p);     /* copy extended attributes, if any */
+      if (attr->data_stream) {
+         int64_t val;
+         while (*p++ != 0)               /* skip extended attributes */
+            { }
+         from_base64(&val, p);
+         attr->data_stream = (int32_t)val;
+      }
    }
-   Dmsg7(400, "unpack_attr FI=%d Type=%d fname=%s attr=%s lname=%s attrEx=%s ds=%d\n",
+   Dmsg7(dbglvl, "unpack_attr FI=%d Type=%d fname=%s attr=%s lname=%s attrEx=%s ds=%d\n",
       attr->file_index, attr->type, attr->fname, attr->attr, attr->lname,
       attr->attrEx, attr->data_stream);
    *attr->ofname = 0;
@@ -237,12 +251,26 @@ void print_ls_output(JCR *jcr, ATTR *attr)
    char ec1[30];
    char en1[30], en2[30];
    char *p, *f;
+   guid_list *guid;
 
+   if (attr->type == FT_DELETED) { /* TODO: change this to get last seen values */
+      bsnprintf(buf, sizeof(buf),
+                "----------   - -        -                - ---------- --------  %s\n", attr->ofname);
+      Dmsg1(dbglvl, "%s", buf);
+      Jmsg(jcr, M_RESTORED, 1, "%s", buf);
+      return;
+   }
+
+   if (!jcr->id_list) {
+      jcr->id_list = new_guid_list();
+   }
+   guid = jcr->id_list;
    p = encode_mode(attr->statp.st_mode, buf);
    p += sprintf(p, "  %2d ", (uint32_t)attr->statp.st_nlink);
-   p += sprintf(p, "%-8.8s %-8.8s", getuser(attr->statp.st_uid, en1, sizeof(en1)),
-                getgroup(attr->statp.st_gid, en2, sizeof(en2)));
-   p += sprintf(p, "%10.10s ", edit_uint64(attr->statp.st_size, ec1));
+   p += sprintf(p, "%-8.8s %-8.8s", 
+                guid->uid_to_name(attr->statp.st_uid, en1, sizeof(en1)),
+                guid->gid_to_name(attr->statp.st_gid, en2, sizeof(en2)));
+   p += sprintf(p, "%12.12s ", edit_int64(attr->statp.st_size, ec1));
    p = encode_time(attr->statp.st_ctime, p);
    *p++ = ' ';
    *p++ = ' ';
@@ -261,6 +289,6 @@ void print_ls_output(JCR *jcr, ATTR *attr)
    }
    *p++ = '\n';
    *p = 0;
-   Dmsg1(20, "%s", buf);
+   Dmsg1(dbglvl, "%s", buf);
    Jmsg(jcr, M_RESTORED, 1, "%s", buf);
 }