]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/findlib/match.c
Restore win32 dir from Branch-5.2 and update it
[bacula/bacula] / bacula / src / findlib / match.c
index 7daf08430d21826690a7d81a4040f983b18dfb20..b1214f3ebf6163797fcefc1083df55286741e7cb 100644 (file)
@@ -1,37 +1,40 @@
 /*
- *     Old style 
+   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.
+*/
+/*
+ *     Old style
  *
  *  Routines used to keep and match include and exclude
  *   filename/pathname patterns.
  *
  *  Note, this file is used for the old style include and
  *   excludes, so is deprecated. The new style code is
- *   found in find.c.   
+ *   found in find.c.
  *  This code is still used for lists in testls and bextract.
  *
  *   Kern E. Sibbald, December MMI
  *
  */
-/*
-   Copyright (C) 2001-2005 Kern Sibbald
-
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License
-   version 2 as amended with additional clauses defined in the
-   file LICENSE in the main source directory.
-
-   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 
-   the file LICENSE for additional details.
-
- */
 
 #include "bacula.h"
 #include "find.h"
+#include "ch.h"
 
-#include <pwd.h>
-#include <grp.h>
 #include <sys/types.h>
 
 #ifndef FNM_LEADING_DIR
@@ -39,7 +42,7 @@
 #endif
 
 /* Fold case in fnmatch() on Win32 */
-#ifdef WIN32
+#ifdef HAVE_WIN32
 static const int fnmode = FNM_CASEFOLD;
 #else
 static const int fnmode = 0;
@@ -49,12 +52,11 @@ static const int fnmode = 0;
 #undef bmalloc
 #define bmalloc(x) sm_malloc(__FILE__, __LINE__, x)
 
-extern const int win32_client;
 
 int
-match_files(JCR *jcr, FF_PKT *ff, int callback(FF_PKT *ff_pkt, void *hpkt, bool), void *his_pkt)
+match_files(JCR *jcr, FF_PKT *ff, int file_save(JCR *, FF_PKT *ff_pkt, bool))
 {
-   ff->callback = callback;
+   ff->file_save = file_save;
 
    struct s_included_file *inc = NULL;
 
@@ -64,7 +66,7 @@ match_files(JCR *jcr, FF_PKT *ff, int callback(FF_PKT *ff_pkt, void *hpkt, bool)
       bstrncat(ff->VerifyOpts, inc->VerifyOpts, sizeof(ff->VerifyOpts));
       Dmsg1(100, "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) {
+         if (find_one_file(jcr, ff, file_save, inc->fname, (dev_t)-1, 1) ==0) {
             return 0;                  /* error return */
          }
       }
@@ -175,10 +177,25 @@ void add_fname_to_include_list(FF_PKT *ff, int prefixed, const char *fname)
          case 'A':
             inc->options |= FO_ACL;
             break;
-         case 'Z':                 /* gzip compression */
-            inc->options |= FO_GZIP;
-            inc->level = *++rp - '0';
-            Dmsg1(200, "Compression level=%d\n", inc->level);
+         case 'Z':                 /* compression */
+            rp++;                   /* skip Z */
+            if (*rp >= '0' && *rp <= '9') {
+               inc->options |= FO_COMPRESS;
+               inc->algo = COMPRESS_GZIP;
+               inc->Compress_level = *rp - '0';
+            }
+               else if (*rp == 'o') {
+               inc->options |= FO_COMPRESS;
+               inc->algo = COMPRESS_LZO1X;
+               inc->Compress_level = 1; /* not used with LZO */
+            }
+            Dmsg2(200, "Compression alg=%d level=%d\n", inc->algo, inc->Compress_level);
+            break;
+         case 'K':
+            inc->options |= FO_NOATIME;
+            break;
+         case 'X':
+            inc->options |= FO_XATTR;
             break;
          default:
             Emsg1(M_ERROR, 0, _("Unknown include/exclude option: %c\n"), *rp);
@@ -197,7 +214,7 @@ void add_fname_to_include_list(FF_PKT *ff, int prefixed, const char *fname)
    len = strlen(p);
    /* Zap trailing slashes.  */
    p += len - 1;
-   while (p > inc->fname && *p == '/') {
+   while (p > inc->fname && IsPathSeparator(*p)) {
       *p-- = 0;
       len--;
    }
@@ -210,7 +227,7 @@ void add_fname_to_include_list(FF_PKT *ff, int prefixed, const char *fname)
          break;
       }
    }
-#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
+#if defined(HAVE_WIN32)
    /* Convert any \'s into /'s */
    for (p=inc->fname; *p; p++) {
       if (*p == '\\') {
@@ -230,7 +247,8 @@ void add_fname_to_include_list(FF_PKT *ff, int prefixed, const char *fname)
          { }
       next->next = inc;
    }
-   Dmsg1(50, "add_fname_to_include fname=%s\n", inc->fname);
+   Dmsg4(100, "add_fname_to_include prefix=%d compres=%d alg= %d fname=%s\n",
+         prefixed, !!(inc->options & FO_COMPRESS), inc->algo, inc->fname);
 }
 
 /*
@@ -244,11 +262,7 @@ void add_fname_to_exclude_list(FF_PKT *ff, const char *fname)
 
    Dmsg1(20, "Add name to exclude: %s\n", fname);
 
-#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
-   if (strchr(fname, '/') || strchr(fname, '\\')) {
-#else
-   if (strchr(fname, '/')) {
-#endif
+   if (first_path_separator(fname) != NULL) {
       list = &ff->excluded_paths_list;
    } else {
       list = &ff->excluded_files_list;
@@ -260,7 +274,7 @@ void add_fname_to_exclude_list(FF_PKT *ff, const char *fname)
    exc->next = *list;
    exc->len = len;
    strcpy(exc->fname, fname);
-#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
+#if defined(HAVE_WIN32)
    /* Convert any \'s into /'s */
    for (char *p=exc->fname; *p; p++) {
       if (*p == '\\') {
@@ -289,7 +303,8 @@ struct s_included_file *get_next_included_file(FF_PKT *ff, struct s_included_fil
     */
    if (inc) {
       ff->flags = inc->options;
-      ff->GZIP_level = inc->level;
+      ff->Compress_algo = inc->algo;
+      ff->Compress_level = inc->Compress_level;
    }
    return inc;
 }
@@ -320,11 +335,11 @@ int file_is_included(FF_PKT *ff, const char *file)
       if (inc->len == len && strcmp(inc->fname, file) == 0) {
          return 1;
       }
-      if (inc->len < len && file[inc->len] == '/' &&
+      if (inc->len < len && IsPathSeparator(file[inc->len]) &&
           strncmp(inc->fname, file, inc->len) == 0) {
          return 1;
       }
-      if (inc->len == 1 && inc->fname[0] == '/') {
+      if (inc->len == 1 && IsPathSeparator(inc->fname[0])) {
          return 1;
       }
    }
@@ -363,13 +378,15 @@ int file_is_excluded(FF_PKT *ff, const char *file)
 {
    const char *p;
 
+#if defined(HAVE_WIN32)
    /*
     *  ***NB*** this removes the drive from the exclude
     *  rule.  Why?????
     */
-   if (win32_client && file[1] == ':') {
+   if (file[1] == ':') {
       file += 2;
    }
+#endif
 
    if (file_in_excluded_list(ff->excluded_paths_list, file)) {
       return 1;
@@ -378,7 +395,7 @@ int file_is_excluded(FF_PKT *ff, const char *file)
    /* Try each component */
    for (p = file; *p; p++) {
       /* Match from the beginning of a component only */
-      if ((p == file || (*p != '/' && *(p-1) == '/'))
+      if ((p == file || (!IsPathSeparator(*p) && IsPathSeparator(p[-1])))
            && file_in_excluded_list(ff->excluded_files_list, p)) {
          return 1;
       }