]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/findlib/find_one.c
Fix #1370 about the implementation of the "Exclude Dir Containing" option on FD.
[bacula/bacula] / bacula / src / findlib / find_one.c
index 7c22ee0a4156957435fdd7ea301c6ed871bb51dd..5619ea43a876caea2a71a642dc514f2761fcf14a 100644 (file)
@@ -1,7 +1,7 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2009 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.
@@ -20,7 +20,7 @@
    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.
@@ -60,7 +60,6 @@ struct f_link {
     struct f_link *next;
     dev_t dev;                        /* device */
     ino_t ino;                        /* inode with device is unique */
-    short linkcount;
     uint32_t FileIndex;               /* Bacula FileIndex of this file */
     char name[1];                     /* The name */
 };
@@ -212,6 +211,22 @@ static bool volume_has_attrlist(const char *fname)
    return false;
 }
 
+/*
+ * check for BSD nodump flag
+ */
+static bool no_dump(JCR *jcr, FF_PKT *ff_pkt)
+{
+#if defined(HAVE_CHFLAGS) && defined(UF_NODUMP)
+   if ( (ff_pkt->flags & FO_HONOR_NODUMP) &&
+        (ff_pkt->statp.st_flags & UF_NODUMP) ) {
+      Jmsg(jcr, M_INFO, 1, _("     NODUMP flag set - will not process %s\n"),
+           ff_pkt->fname);
+      return true;                    /* do not backup this file */
+   }
+#endif
+   return false;                      /* do backup */
+}
+
 /* check if a file have changed during backup and display an error */
 bool has_file_changed(JCR *jcr, FF_PKT *ff_pkt)
 {
@@ -258,19 +273,19 @@ bool has_file_changed(JCR *jcr, FF_PKT *ff_pkt)
 }
 
 /*
- * In incremental/diffential or accurate backup, we
- * say if the current file has changed.
+ * For incremental/diffential or accurate backups, we
+ *   determine if the current file has changed.
  */
 static bool check_changes(JCR *jcr, FF_PKT *ff_pkt)
 {
-   /* in special mode (like accurate backup), user can 
+   /* in special mode (like accurate backup), the programmer can 
     * choose his comparison function.
     */
    if (ff_pkt->check_fct) {
       return ff_pkt->check_fct(jcr, ff_pkt);
    }
 
-   /* in normal modes (incr/diff), we use this default
+   /* For normal backups (incr/diff), we use this default
     * behaviour
     */
    if (ff_pkt->incremental &&
@@ -354,6 +369,16 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt,
       }
       ff_pkt->volhas_attrlist = volume_has_attrlist(fname);
    }
+
+   /*
+    * Ignore this entry if no_dump() returns true
+    */
+   if (no_dump(jcr, ff_pkt)) {
+           Dmsg1(100, "'%s' ignored (NODUMP flag set)\n",
+                 ff_pkt->fname);
+           return 1;
+   }
+
    /*
     * If this is an Incremental backup, see if file was modified
     * since our last "save_time", presumably the last Full save
@@ -415,12 +440,17 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt,
              lp->dev == (dev_t)ff_pkt->statp.st_dev) {
              /* If we have already backed up the hard linked file don't do it again */
              if (strcmp(lp->name, fname) == 0) {
+                Dmsg2(400, "== Name identical skip FI=%d file=%s\n", lp->FileIndex, fname);
                 return 1;             /* ignore */
              }
              ff_pkt->link = lp->name;
              ff_pkt->type = FT_LNKSAVED;       /* Handle link, file already saved */
              ff_pkt->LinkFI = lp->FileIndex;
-             return handle_file(jcr, ff_pkt, top_level);
+             ff_pkt->linked = 0;
+             rtn_stat = handle_file(jcr, ff_pkt, top_level);
+             Dmsg3(400, "FT_LNKSAVED FI=%d LinkFI=%d file=%s\n", 
+                ff_pkt->FileIndex, lp->FileIndex, lp->name);
+             return rtn_stat;
          }
 
       /* File not previously dumped. Chain it into our list. */
@@ -428,10 +458,12 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt,
       lp = (struct f_link *)bmalloc(sizeof(struct f_link) + len);
       lp->ino = ff_pkt->statp.st_ino;
       lp->dev = ff_pkt->statp.st_dev;
+      lp->FileIndex = 0;                  /* set later */
       bstrncpy(lp->name, fname, len);
       lp->next = ff_pkt->linkhash[linkhash];
       ff_pkt->linkhash[linkhash] = lp;
       ff_pkt->linked = lp;            /* mark saved link */
+      Dmsg2(400, "added to hash FI=%d file=%s\n", ff_pkt->FileIndex, lp->name);
    } else {
       ff_pkt->linked = NULL;
    }
@@ -454,6 +486,8 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt,
       if (ff_pkt->linked) {
          ff_pkt->linked->FileIndex = ff_pkt->FileIndex;
       }
+      Dmsg3(400, "FT_REG FI=%d linked=%d file=%s\n", ff_pkt->FileIndex, 
+         ff_pkt->linked ? 1 : 0, fname);
       if (ff_pkt->flags & FO_KEEPATIME) {
          utime(fname, &restore_times);
       }       
@@ -518,21 +552,21 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt,
        * (or what is defined for IgnoreDir in this fileset) exists
        */
       if (ff_pkt->ignoredir != NULL) {
-        struct stat sb;
-        char fname[MAXPATHLEN];
+         struct stat sb;
+         char fname[MAXPATHLEN];
 
-        if (strlen(ff_pkt->fname) + strlen("/") +
-           strlen(ff_pkt->ignoredir) + 1 > MAXPATHLEN)
-           return 1;   /* Is this wisdom? */
+         if (strlen(ff_pkt->fname) + strlen("/") +
+            strlen(ff_pkt->ignoredir) + 1 > MAXPATHLEN)
+            return 1;   /* Is this wisdom? */
 
-        strcpy(fname, ff_pkt->fname);
-        strcat(fname, "/");
-        strcat(fname, ff_pkt->ignoredir);
-        if (stat(fname, &sb) == 0) {
+         strcpy(fname, ff_pkt->fname);
+         strcat(fname, "/");
+         strcat(fname, ff_pkt->ignoredir);
+         if (stat(fname, &sb) == 0) {
             Dmsg2(100, "Directory '%s' ignored (found %s)\n",
-              ff_pkt->fname, ff_pkt->ignoredir);
+               ff_pkt->fname, ff_pkt->ignoredir);
             return 1;      /* Just ignore this directory */
-        }
+         }
       }
 
       /* Build a canonical directory name with a trailing slash in link var */
@@ -557,9 +591,11 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt,
        * We have set st_rdev to 1 if it is a reparse point, otherwise 0,
        *  if st_rdev is 2, it is a mount point 
        */
-      if (have_win32_api() && ff_pkt->statp.st_rdev == 1) {
+#if defined(HAVE_WIN32)
+      if (ff_pkt->statp.st_rdev == WIN32_REPARSE_POINT) {
          ff_pkt->type = FT_REPARSE;
       }
+#endif 
       /*
        * Note, we return the directory to the calling program (handle_file)
        * when we first see the directory (FT_DIRBEGIN.
@@ -597,10 +633,15 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt,
        * to cross, or we may be restricted by a list of permitted
        * file systems.
        */
+      bool is_win32_mount_point = false;
+#if defined(HAVE_WIN32)
+      is_win32_mount_point = ff_pkt->statp.st_rdev == WIN32_MOUNT_POINT;
+#endif
       if (!top_level && ff_pkt->flags & FO_NO_RECURSION) {
          ff_pkt->type = FT_NORECURSE;
          recurse = false;
-      } else if (!top_level && parent_device != ff_pkt->statp.st_dev) {
+      } else if (!top_level && (parent_device != ff_pkt->statp.st_dev ||
+                 is_win32_mount_point)) {
          if(!(ff_pkt->flags & FO_MULTIFS)) {
             ff_pkt->type = FT_NOFSCHG;
             recurse = false;