]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/attr.c
dhb Medialist : created context menu function and moved lines which create
[bacula/bacula] / bacula / src / lib / attr.c
index 443260f1d7aec8d216c01367e9e2f1fa05e4ad60..47a5ee1b9ed172652bc333dd6122b45f11a69394 100644 (file)
@@ -1,35 +1,41 @@
 /*
  *   attr.c  Unpack an Attribute record returned from the tape
  *
- *    Kern Sibbald, June MMIII (code pulled from filed/restore.c and updated)
+ *    Kern Sibbald, June MMIII  (code pulled from filed/restore.c and updated)
  *
  *   Version $Id$
  */
-
 /*
-   Copyright (C) 2003-2004 Kern Sibbald and John Walker
+   Bacula® - The Network Backup Solution
+
+   Copyright (C) 2003-2006 Free Software Foundation Europe e.V.
 
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
+   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
+   License as published by the Free Software Foundation plus additions
+   that are listed in the file LICENSE.
 
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
    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 along with this program; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-   MA 02111-1307, USA.
+   You should have received a copy of the GNU 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.
+   The licensor of Bacula is the Free Software Foundation Europe
+   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+   Switzerland, email:ftf@fsfeurope.org.
+*/
 
 #include "bacula.h"
 #include "jcr.h"
 
-extern const int win32_client;
 
 ATTR *new_attr()
 {
@@ -54,55 +60,55 @@ int unpack_attributes_record(JCR *jcr, int32_t stream, char *rec, ATTR *attr)
    char *p;
    /*
     * An Attributes record consists of:
-    *   File_index
-    *   Type   (FT_types)
-    *   Filename
-    *   Attributes
-    *   Link name (if file linked i.e. FT_LNK)
-    *   Extended attributes (Win32)
+    *    File_index
+    *    Type   (FT_types)
+    *    Filename
+    *    Attributes
+    *    Link name (if file linked i.e. FT_LNK)
+    *    Extended attributes (Win32)
     *  plus optional values determined by AR_ flags in upper bits of Type
-    *   Data_stream
+    *    Data_stream
     *
     */
    attr->stream = stream;
-   Dmsg1(100, "Attr: %s\n", rec);
-   if (sscanf(rec, "%d %d", &attr->file_index, &attr->type) != 2) {
+   Dmsg1(400, "Attr: %s\n", rec);
+   if (sscanf(rec, "%ld %ld", &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);
       return 0;
    }
-   Dmsg2(100, "Got Attr: FilInx=%d type=%d\n", attr->file_index, attr->type);
+   Dmsg2(400, "Got Attr: FilInx=%d type=%d\n", attr->file_index, attr->type);
    if (attr->type & AR_DATA_STREAM) {
       attr->data_stream = 1;
    } else {
       attr->data_stream = 0;
    }
-   attr->type &= FT_MASK;            /* keep only type bits */
+   attr->type &= FT_MASK;             /* keep only type bits */
    p = rec;
    while (*p++ != ' ')               /* skip record file index */
       { }
    while (*p++ != ' ')               /* skip type */
       { }
 
-   attr->fname = p;                  /* set filname position */
-   while (*p++ != 0)                 /* skip filename */
+   attr->fname = p;                   /* set filname position */
+   while (*p++ != 0)                  /* skip filename */
       { }
-   attr->attr = p;                   /* set attributes position */
-   while (*p++ != 0)                 /* skip attributes */
+   attr->attr = p;                    /* set attributes position */
+   while (*p++ != 0)                  /* skip attributes */
       { }
-   attr->lname = p;                  /* set link position */
-   while (*p++ != 0)                 /* skip link */
+   attr->lname = p;                   /* set link position */
+   while (*p++ != 0)                  /* skip link */
       { }
-   pm_strcpy(attr->attrEx, p);       /* copy extended attributes, if any */
+   pm_strcpy(attr->attrEx, p);        /* copy extended attributes, if any */
 
    if (attr->data_stream) {
       int64_t val;
-      while (*p++ != 0)              /* skip extended attributes */
-        { }
+      while (*p++ != 0)               /* skip extended attributes */
+         { }
       from_base64(&val, p);
       attr->data_stream = (int32_t)val;
    }
-   Dmsg7(200, "unpack_attr FI=%d Type=%d fname=%s attr=%s lname=%s attrEx=%s ds=%d\n",
+   Dmsg7(400, "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;
@@ -110,9 +116,25 @@ int unpack_attributes_record(JCR *jcr, int32_t stream, char *rec, ATTR *attr)
    return 1;
 }
 
+#if defined(HAVE_WIN32)
+static void strip_double_slashes(char *fname)
+{
+   char *p = fname;
+   while (p && *p) {
+      p = strpbrk(p, "/\\");
+      if (p != NULL) {
+         if (IsPathSeparator(p[1])) {
+            strcpy(p, p+1);
+         }
+         p++;
+      }
+   }
+}
+#endif
+
 /*
  * Build attr->ofname from attr->fname and
- *      attr->olname from attr->olname
+ *       attr->olname from attr->olname
  */
 void build_attr_output_fnames(JCR *jcr, ATTR *attr)
 {
@@ -121,9 +143,9 @@ void build_attr_output_fnames(JCR *jcr, ATTR *attr)
     * files are put where the user wants.
     *
     * We do a little jig here to handle Win32 files with
-    *  a drive letter -- we simply change the drive
-    *  from, for example, c: to c/ for
-    *  every filename if a prefix is supplied.
+    *   a drive letter -- we simply change the drive
+    *   from, for example, c: to c/ for
+    *   every filename if a prefix is supplied.
     *
     */
    if (jcr->where[0] == 0) {
@@ -133,42 +155,53 @@ void build_attr_output_fnames(JCR *jcr, ATTR *attr)
       const char *fn;
       int wherelen = strlen(jcr->where);
       pm_strcpy(attr->ofname, jcr->where);  /* copy prefix */
-      if (win32_client && attr->fname[1] == ':') {
-        attr->fname[1] = '/';     /* convert : to / */
+#if defined(HAVE_WIN32)
+      if (attr->fname[1] == ':') {
+         attr->fname[1] = '/';     /* convert : to / */
       }
-      fn = attr->fname;           /* take whole name */
+#endif
+      fn = attr->fname;            /* take whole name */
       /* Ensure where is terminated with a slash */
-      if (jcr->where[wherelen-1] != '/' && fn[0] != '/') {
-        pm_strcat(attr->ofname, "/");
+      if (!IsPathSeparator(jcr->where[wherelen-1]) && !IsPathSeparator(fn[0])) {
+         pm_strcat(attr->ofname, "/");
       }
       pm_strcat(attr->ofname, fn); /* copy rest of name */
       /*
        * Fixup link name -- if it is an absolute path
        */
       if (attr->type == FT_LNKSAVED || attr->type == FT_LNK) {
-        bool add_link;
-        /* Always add prefix to hard links (FT_LNKSAVED) and
-         *  on user request to soft links
-         */
-        if (attr->lname[0] == '/' &&
-            (attr->type == FT_LNKSAVED || jcr->prefix_links)) {
-           pm_strcpy(attr->olname, jcr->where);
-           add_link = true;
-        } else {
-           attr->olname[0] = 0;
-           add_link = false;
-        }
-        if (win32_client && attr->lname[1] == ':') {
-           attr->lname[1] = '/';    /* turn : into / */
-        }
-        fn = attr->lname;       /* take whole name */
-        /* Ensure where is terminated with a slash */
-        if (add_link && jcr->where[wherelen-1] != '/' && fn[0] != '/') {
-           pm_strcat(attr->olname, "/");
-        }
-        pm_strcat(attr->olname, fn);     /* copy rest of link */
+         bool add_link;
+         /* Always add prefix to hard links (FT_LNKSAVED) and
+          *  on user request to soft links
+          */
+         if (IsPathSeparator(attr->lname[0]) &&
+             (attr->type == FT_LNKSAVED || jcr->prefix_links)) {
+            pm_strcpy(attr->olname, jcr->where);
+            add_link = true;
+         } else {
+            attr->olname[0] = 0;
+            add_link = false;
+         }
+
+#if defined(HAVE_WIN32)
+         if (attr->lname[1] == ':') {
+            attr->lname[1] = '/';    /* turn : into / */
+         }
+#endif
+         fn = attr->lname;       /* take whole name */
+         /* Ensure where is terminated with a slash */
+         if (add_link && 
+            !IsPathSeparator(jcr->where[wherelen-1]) && 
+            !IsPathSeparator(fn[0])) {
+            pm_strcat(attr->olname, "/");
+         }
+         pm_strcat(attr->olname, fn);     /* copy rest of link */
       }
    }
+#if defined(HAVE_WIN32)
+   strip_double_slashes(attr->ofname);
+   strip_double_slashes(attr->olname);
+#endif
 }
 
 extern char *getuser(uid_t uid, char *name, int len);
@@ -187,8 +220,8 @@ void print_ls_output(JCR *jcr, ATTR *attr)
    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, "%8.8s ", edit_uint64(attr->statp.st_size, ec1));
+                getgroup(attr->statp.st_gid, en2, sizeof(en2)));
+   p += sprintf(p, "%10.10s ", edit_uint64(attr->statp.st_size, ec1));
    p = encode_time(attr->statp.st_ctime, p);
    *p++ = ' ';
    *p++ = ' ';
@@ -202,7 +235,7 @@ void print_ls_output(JCR *jcr, ATTR *attr)
       *p++ = ' ';
       /* Copy link name */
       for (f=attr->olname; *f && (p-buf) < (int)sizeof(buf)-10; ) {
-        *p++ = *f++;
+         *p++ = *f++;
       }
    }
    *p++ = '\n';