]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/findlib/find_one.c
Restore win32 dir from Branch-5.2 and update it
[bacula/bacula] / bacula / src / findlib / find_one.c
index 36708d343384d7f6ad3fc78e371962f7fe48efcd..8e4beb931275ea4b3bfc8b007a49b95b60705f01 100644 (file)
@@ -1,29 +1,20 @@
 /*
-   Bacula® - The Network Backup Solution
-
-   Copyright (C) 2000-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 three of the GNU Affero General Public
-   License as published by the Free Software Foundation and included
-   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
-   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 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 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.
+   Bacula(R) - The Network Backup Solution
+
+   Copyright (C) 2000-2018 Kern Sibbald
+
+   The original author of Bacula is Kern Sibbald, with contributions
+   from many others, a complete list can be found in the file AUTHORS.
+
+   You may use this file and others of this release according to the
+   license defined in the LICENSE file, which includes the Affero General
+   Public License, v3.0 ("AGPLv3") and some additional permissions and
+   terms pursuant to its AGPLv3 Section 7.
+
+   This notice must be preserved when any source code is
+   conveyed and/or propagated.
+
+   Bacula(R) is a registered trademark of Kern Sibbald.
 */
 /*
 
@@ -87,7 +78,7 @@ static inline int LINKHASH(const struct stat &info)
 /*
  * Create a new directory Find File packet, but copy
  *   some of the essential info from the current packet.
- *   However, be careful to zero out the rest of the 
+ *   However, be careful to zero out the rest of the
  *   packet.
  */
 static FF_PKT *new_dir_ff_pkt(FF_PKT *ff_pkt)
@@ -97,12 +88,23 @@ static FF_PKT *new_dir_ff_pkt(FF_PKT *ff_pkt)
    dir_ff_pkt->fname = bstrdup(ff_pkt->fname);
    dir_ff_pkt->link = bstrdup(ff_pkt->link);
    dir_ff_pkt->sys_fname = get_pool_memory(PM_FNAME);
+
+   if (ff_pkt->strip_snap_path) {
+      dir_ff_pkt->fname_save = get_pool_memory(PM_FNAME);
+      dir_ff_pkt->link_save = get_pool_memory(PM_FNAME);
+      pm_strcpy(dir_ff_pkt->fname_save, ff_pkt->fname_save);
+      pm_strcpy(dir_ff_pkt->link_save, ff_pkt->link_save);
+
+   } else {
+      dir_ff_pkt->fname_save = NULL;
+      dir_ff_pkt->link_save = NULL;
+   }
+
    dir_ff_pkt->included_files_list = NULL;
    dir_ff_pkt->excluded_files_list = NULL;
    dir_ff_pkt->excluded_paths_list = NULL;
    dir_ff_pkt->linkhash = NULL;
-   dir_ff_pkt->fname_save = NULL;
-   dir_ff_pkt->link_save = NULL;
+   dir_ff_pkt->ignoredir_fname = NULL;
    return dir_ff_pkt;
 }
 
@@ -134,7 +136,7 @@ static int accept_fstype(FF_PKT *ff, void *dummy) {
 
    if (ff->fstypes.size()) {
       accept = false;
-      if (!fstype(ff->fname, fs, sizeof(fs))) {
+      if (!fstype(ff, fs, sizeof(fs))) {
          Dmsg1(50, "Cannot determine file system type for \"%s\"\n", ff->fname);
       } else {
          for (i = 0; i < ff->fstypes.size(); ++i) {
@@ -240,7 +242,7 @@ bool has_file_changed(JCR *jcr, FF_PKT *ff_pkt)
 
    if (lstat(ff_pkt->fname, &statp) != 0) {
       berrno be;
-      Jmsg(jcr, M_WARNING, 0, 
+      Jmsg(jcr, M_WARNING, 0,
            _("Cannot stat file %s: ERR=%s\n"),ff_pkt->fname,be.bstrerror());
       return true;
    }
@@ -258,20 +260,12 @@ bool has_file_changed(JCR *jcr, FF_PKT *ff_pkt)
             (int64_t)ff_pkt->statp.st_ctime, (int64_t)statp.st_ctime);
       return true;
    }
-  
-   if (statp.st_size != ff_pkt->statp.st_size) {
-      /* TODO: add size change */
-      Jmsg(jcr, M_ERROR, 0, _("%s size changed during backup.\n"),ff_pkt->fname);
-      Dmsg3(50, "%s size (%lld) changed during backup (%lld).\n", ff_pkt->fname,
-            (int64_t)ff_pkt->statp.st_size, (int64_t)statp.st_size);
-      return true;
-   }
 
-   if ((statp.st_blksize != ff_pkt->statp.st_blksize) ||
-       (statp.st_blocks  != ff_pkt->statp.st_blocks)) {
-      Jmsg(jcr, M_ERROR, 0, _("%s size changed during backup.\n"),ff_pkt->fname);
+   if ((int64_t)statp.st_size != (int64_t)ff_pkt->statp.st_size) {
+      Jmsg(jcr, M_ERROR, 0, _("%s size of %lld changed during backup to %lld.n"),ff_pkt->fname,
+         (int64_t)ff_pkt->statp.st_size, (int64_t)statp.st_size);
       Dmsg3(50, "%s size (%lld) changed during backup (%lld).\n", ff_pkt->fname,
-            (int64_t)ff_pkt->statp.st_blocks, (int64_t)statp.st_blocks);
+            (int64_t)ff_pkt->statp.st_size, (int64_t)statp.st_size);
       return true;
    }
 
@@ -284,7 +278,7 @@ bool has_file_changed(JCR *jcr, FF_PKT *ff_pkt)
  */
 bool check_changes(JCR *jcr, FF_PKT *ff_pkt)
 {
-   /* in special mode (like accurate backup), the programmer can 
+   /* in special mode (like accurate backup), the programmer can
     * choose his comparison function.
     */
    if (ff_pkt->check_fct) {
@@ -297,10 +291,10 @@ bool check_changes(JCR *jcr, FF_PKT *ff_pkt)
    if (ff_pkt->incremental &&
        (ff_pkt->statp.st_mtime < ff_pkt->save_time &&
         ((ff_pkt->flags & FO_MTIMEONLY) ||
-         ff_pkt->statp.st_ctime < ff_pkt->save_time))) 
+         ff_pkt->statp.st_ctime < ff_pkt->save_time)))
    {
       return false;
-   } 
+   }
 
    return true;
 }
@@ -308,7 +302,6 @@ bool check_changes(JCR *jcr, FF_PKT *ff_pkt)
 static bool have_ignoredir(FF_PKT *ff_pkt)
 {
    struct stat sb;
-   char tmp_name[MAXPATHLEN];
    char *ignoredir;
 
    /* Ensure that pointers are defined */
@@ -316,25 +309,22 @@ static bool have_ignoredir(FF_PKT *ff_pkt)
       return false;
    }
    ignoredir = ff_pkt->fileset->incexe->ignoredir;
-   
+
    if (ignoredir) {
-      if (strlen(ff_pkt->fname) + strlen(ignoredir) + 2 > MAXPATHLEN) {
-         return false;
+      if (!ff_pkt->ignoredir_fname) {
+         ff_pkt->ignoredir_fname = get_pool_memory(PM_FNAME);
       }
-
-      strcpy(tmp_name, ff_pkt->fname);
-      strcat(tmp_name, "/");
-      strcat(tmp_name, ignoredir);
-      if (stat(tmp_name, &sb) == 0) {
+      Mmsg(ff_pkt->ignoredir_fname, "%s/%s", ff_pkt->fname, ignoredir);
+      if (stat(ff_pkt->ignoredir_fname, &sb) == 0) {
          Dmsg2(100, "Directory '%s' ignored (found %s)\n",
                ff_pkt->fname, ignoredir);
          return true;      /* Just ignore this directory */
-      } 
+      }
    }
    return false;
 }
 
-/* 
+/*
  * When the current file is a hardlink, the backup code can compute
  * the checksum and store it into the link_t structure.
  */
@@ -359,7 +349,7 @@ ff_pkt_set_link_digest(FF_PKT *ff_pkt,
  *  descending into a directory.
  */
 int
-find_one_file(JCR *jcr, FF_PKT *ff_pkt, 
+find_one_file(JCR *jcr, FF_PKT *ff_pkt,
                int handle_file(JCR *jcr, FF_PKT *ff, bool top_level),
                char *fname, dev_t parent_device, bool top_level)
 {
@@ -396,7 +386,7 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt,
 
          char fs[100];
 
-         if (!fstype(ff_pkt->fname, fs, sizeof(fs))) {
+         if (!fstype(ff_pkt, fs, sizeof(fs))) {
              bstrncpy(fs, "unknown", sizeof(fs));
          }
 
@@ -435,8 +425,8 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt,
     * since our last "save_time", presumably the last Full save
     * or Incremental.
     */
-   if (   !S_ISDIR(ff_pkt->statp.st_mode) 
-       && !check_changes(jcr, ff_pkt)) 
+   if (   !S_ISDIR(ff_pkt->statp.st_mode)
+       && !check_changes(jcr, ff_pkt))
    {
       Dmsg1(500, "Non-directory incremental: %s\n", ff_pkt->fname);
       ff_pkt->type = FT_NOCHG;
@@ -458,6 +448,7 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt,
           ff_pkt->ff_errno = errno;
           return handle_file(jcr, ff_pkt, top_level);
        }
+       return -1; /* ignore */
    }
 #endif
 
@@ -501,7 +492,7 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt,
              ff_pkt->digest_stream = lp->digest_stream;
              ff_pkt->digest_len = lp->digest_len;
              rtn_stat = handle_file(jcr, ff_pkt, top_level);
-             Dmsg3(400, "FT_LNKSAVED FI=%d LinkFI=%d file=%s\n", 
+             Dmsg3(400, "FT_LNKSAVED FI=%d LinkFI=%d file=%s\n",
                 ff_pkt->FileIndex, lp->FileIndex, lp->name);
              return rtn_stat;
          }
@@ -542,11 +533,11 @@ 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, 
+      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);
-      }       
+      }
       return rtn_stat;
 
 
@@ -613,12 +604,12 @@ 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 st_rdev is 2, it is a mount point
        */
 #if defined(HAVE_WIN32)
       /*
        * A reparse point (WIN32_REPARSE_POINT)
-       *  is something special like one of the following: 
+       *  is something special like one of the following:
        *  IO_REPARSE_TAG_DFS              0x8000000A
        *  IO_REPARSE_TAG_DFSR             0x80000012
        *  IO_REPARSE_TAG_HSM              0xC0000004
@@ -638,7 +629,7 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt,
       } else if (ff_pkt->statp.st_rdev == WIN32_JUNCTION_POINT) {
          ff_pkt->type = FT_JUNCTION;
       }
-#endif 
+#endif
       /*
        * Note, we return the directory to the calling program (handle_file)
        * when we first see the directory (FT_DIRBEGIN.
@@ -833,7 +824,7 @@ int term_find_one(FF_PKT *ff)
    int count = 0;
    int i;
 
-   
+
    if (ff->linkhash == NULL) return 0;
 
    for (i =0 ; i < LINK_HASHTABLE_SIZE; i ++) {