]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/findlib/find.c
- Use different share mode when opening files on WinMe/98/95 since
[bacula/bacula] / bacula / src / findlib / find.c
index b74f90c2d4561a793343996b29273c708b4d9ab5..c8a510f6d8c6f3c9ae2103969b755f91b65f163c 100644 (file)
@@ -1,6 +1,9 @@
 /*
  * Main routine for finding files on a file system.
- *  The heart of the work is done in find_one.c
+ *  The heart of the work to find the files on the
+ *    system is done in find_one.c. Here we have the
+ *    higher level control as well as the matching
+ *    routines for the new syntax Options resource.
  *
  *  Kern E. Sibbald, MM
  */
@@ -28,7 +31,6 @@
 #include "bacula.h"
 #include "find.h"
 
-
 int32_t name_max;             /* filename max length */
 int32_t path_max;             /* path name max length */
 
@@ -39,6 +41,13 @@ int32_t path_max;           /* path name max length */
 static int our_callback(FF_PKT *ff, void *hpkt);
 static bool accept_file(FF_PKT *ff);
 
+/* Fold case in fnmatch() on Win32 */
+#ifdef WIN32
+static const int fnmode = FNM_CASEFOLD;
+#else
+static const int fnmode = 0;
+#endif
+
 
 /* 
  * Initialize the find files "global" variables
@@ -112,7 +121,8 @@ find_files(JCR *jcr, FF_PKT *ff, int callback(FF_PKT *ff_pkt, void *hpkt), void
    if (fileset) {
       int i, j;
       ff->flags = 0;
-      ff->VerifyOpts[0] = 0;
+      ff->VerifyOpts[0] = 'V';
+      ff->VerifyOpts[1] = 0;
       for (i=0; i<fileset->include_list.size(); i++) {
         findINCEXE *incexe = (findINCEXE *)fileset->include_list.get(i);
         fileset->incexe = incexe;
@@ -124,7 +134,7 @@ find_files(JCR *jcr, FF_PKT *ff, int callback(FF_PKT *ff_pkt, void *hpkt), void
            findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
            ff->flags |= fo->flags;
            ff->GZIP_level = fo->GZIP_level;
-           bstrncpy(ff->VerifyOpts, fo->VerifyOpts, sizeof(ff->VerifyOpts)); 
+           bstrncat(ff->VerifyOpts, fo->VerifyOpts, sizeof(ff->VerifyOpts)); 
         }
         for (j=0; j<incexe->name_list.size(); j++) {
             Dmsg1(400, "F %s\n", (char *)incexe->name_list.get(j));
@@ -140,7 +150,7 @@ find_files(JCR *jcr, FF_PKT *ff, int callback(FF_PKT *ff_pkt, void *hpkt), void
       /* This is the old deprecated way */
       while (!job_canceled(jcr) && (inc = get_next_included_file(ff, inc))) {
         /* Copy options for this file */
-        bstrncpy(ff->VerifyOpts, inc->VerifyOpts, sizeof(ff->VerifyOpts)); 
+        bstrncat(ff->VerifyOpts, inc->VerifyOpts, sizeof(ff->VerifyOpts)); 
          Dmsg1(50, "find_files: file=%s\n", inc->fname);
         if (!file_is_excluded(ff, inc->fname)) {
            if (find_one_file(jcr, ff, callback, his_pkt, inc->fname, (dev_t)-1, 1) ==0) {
@@ -160,16 +170,30 @@ static bool accept_file(FF_PKT *ff)
 
    for (j=0; j<incexe->opts_list.size(); j++) {
       findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
+      ff->flags = fo->flags;
+      ff->GZIP_level = fo->GZIP_level;
+      ff->reader = fo->reader;
+      ff->writer = fo->writer;
       for (k=0; k<fo->wild.size(); k++) {
-        if (fnmatch((char *)fo->wild.get(k), ff->fname, 0) == 0) {
-           ff->flags = fo->flags;
-           ff->GZIP_level = fo->GZIP_level;
+        if (fnmatch((char *)fo->wild.get(k), ff->fname, fnmode) == 0) {
            if (ff->flags & FO_EXCLUDE) {
               return false;          /* reject file */
            }
            return true;              /* accept file */
         }
       }
+#ifndef WIN32
+      for (k=0; k<fo->regex.size(); k++) {
+        const int nmatch = 30;
+        regmatch_t pmatch[nmatch];
+        if (regexec((regex_t *)fo->regex.get(k), ff->fname, nmatch, pmatch,  0) == 0) {
+           if (ff->flags & FO_EXCLUDE) {
+              return false;          /* reject file */
+           }
+           return true;              /* accept file */
+        }
+      }
+#endif
    }
 
    for (i=0; i<fileset->exclude_list.size(); i++) {
@@ -177,14 +201,14 @@ static bool accept_file(FF_PKT *ff)
       for (j=0; j<incexe->opts_list.size(); j++) {
         findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
         for (k=0; k<fo->wild.size(); k++) {
-           if (fnmatch((char *)fo->wild.get(k), ff->fname, 0) == 0) {
+           if (fnmatch((char *)fo->wild.get(k), ff->fname, fnmode) == 0) {
                Dmsg1(400, "Reject wild1: %s\n", ff->fname);
               return false;          /* reject file */
            }
         }
       }
       for (j=0; j<incexe->name_list.size(); j++) {
-        if (fnmatch((char *)incexe->name_list.get(j), ff->fname, 0) == 0) {
+        if (fnmatch((char *)incexe->name_list.get(j), ff->fname, fnmode) == 0) {
             Dmsg1(400, "Reject wild2: %s\n", ff->fname);
            return false;          /* reject file */
         }
@@ -205,12 +229,11 @@ static int our_callback(FF_PKT *ff, void *hpkt)
    case FT_NOFOLLOW:
    case FT_NOSTAT:
    case FT_NOCHG:
-   case FT_DIRNOCHG:
    case FT_ISARCH:
    case FT_NORECURSE:
    case FT_NOFSCHG:
    case FT_NOOPEN:
-      return ff->callback(ff, hpkt);
+//    return ff->callback(ff, hpkt);
 
    /* These items can be filtered */
    case FT_LNKSAVED:
@@ -222,6 +245,7 @@ static int our_callback(FF_PKT *ff, void *hpkt)
    case FT_RAW:
    case FT_FIFO:
    case FT_SPEC:
+   case FT_DIRNOCHG:
       if (accept_file(ff)) {
         return ff->callback(ff, hpkt);
       } else {