X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Ffindlib%2Fmatch.c;h=a1b811418daf8ba1c644b7ad5f11c15e72b47553;hb=f96efc7d30726fe864e38e2d7d15f8add3d22ee7;hp=95a574572f846610c02b7e8a425dcd6c4f7cccb0;hpb=ff8f6a055709010d9d698b2f98e52e3a7148389c;p=bacula%2Fbacula diff --git a/bacula/src/findlib/match.c b/bacula/src/findlib/match.c index 95a574572f..a1b811418d 100644 --- a/bacula/src/findlib/match.c +++ b/bacula/src/findlib/match.c @@ -2,11 +2,15 @@ * 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 + * * Kern E. Sibbald, December MMI * */ /* - Copyright (C) 2001-2003 Kern Sibbald and John Walker + Copyright (C) 2001-2004 Kern Sibbald and John Walker This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -36,6 +40,14 @@ #define FNM_LEADING_DIR 0 #endif +/* Fold case in fnmatch() on Win32 */ +#ifdef WIN32 +static const int fnmode = FNM_CASEFOLD; +#else +static const int fnmode = 0; +#endif + + #undef bmalloc #define bmalloc(x) sm_malloc(__FILE__, __LINE__, x) @@ -80,11 +92,12 @@ void term_include_exclude_files(FF_PKT *ff) /* * Add a filename to list of included files */ -void add_fname_to_include_list(FF_PKT *ff, int prefixed, char *fname) +void add_fname_to_include_list(FF_PKT *ff, int prefixed, const char *fname) { int len, j; struct s_included_file *inc; char *p; + const char *rp; len = strlen(fname); @@ -96,8 +109,8 @@ void add_fname_to_include_list(FF_PKT *ff, int prefixed, char *fname) /* prefixed = preceded with options */ if (prefixed) { - for (p=fname; *p && *p != ' '; p++) { - switch (*p) { + for (rp=fname; *rp && *rp != ' '; rp++) { + switch (*rp) { case 'a': /* alway replace */ case '0': /* no option */ break; @@ -133,8 +146,8 @@ void add_fname_to_include_list(FF_PKT *ff, int prefixed, char *fname) break; case 'V': /* verify options */ /* Copy Verify Options */ - for (j=0; *p && *p != ':'; p++) { - inc->VerifyOpts[j] = *p; + for (j=0; *rp && *rp != ':'; rp++) { + inc->VerifyOpts[j] = *rp; if (j < (int)sizeof(inc->VerifyOpts) - 1) { j++; } @@ -144,24 +157,27 @@ void add_fname_to_include_list(FF_PKT *ff, int prefixed, char *fname) case 'w': inc->options |= FO_IF_NEWER; break; + case 'A': + inc->options |= FO_ACL; + break; case 'Z': /* gzip compression */ inc->options |= FO_GZIP; - inc->level = *++p - '0'; + inc->level = *++rp - '0'; Dmsg1(200, "Compression level=%d\n", inc->level); break; default: - Emsg1(M_ERROR, 0, "Unknown include/exclude option: %c\n", *p); + Emsg1(M_ERROR, 0, "Unknown include/exclude option: %c\n", *rp); break; } } /* Skip past space(s) */ - for ( ; *p == ' '; p++) + for ( ; *rp == ' '; rp++) {} } else { - p = fname; + rp = fname; } - strcpy(inc->fname, p); + strcpy(inc->fname, rp); p = inc->fname; len = strlen(p); /* Zap trailing slashes. */ @@ -206,22 +222,18 @@ void add_fname_to_include_list(FF_PKT *ff, int prefixed, char *fname) * We add an exclude name to either the exclude path * list or the exclude filename list. */ -void add_fname_to_exclude_list(FF_PKT *ff, char *fname) +void add_fname_to_exclude_list(FF_PKT *ff, const char *fname) { int len; struct s_excluded_file *exc, **list; -#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) - /* Convert any \'s into /'s */ - for (char *p=fname; *p; p++) { - if (*p == '\\') { - *p = '/'; - } - } -#endif 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 list = &ff->excluded_paths_list; } else { list = &ff->excluded_files_list; @@ -233,6 +245,14 @@ void add_fname_to_exclude_list(FF_PKT *ff, char *fname) exc->next = *list; exc->len = len; strcpy(exc->fname, fname); +#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) + /* Convert any \'s into /'s */ + for (char *p=exc->fname; *p; p++) { + if (*p == '\\') { + *p = '/'; + } + } +#endif *list = exc; } @@ -264,14 +284,14 @@ struct s_included_file *get_next_included_file(FF_PKT *ff, struct s_included_fil * file is included possibly with wild-cards. */ -int file_is_included(FF_PKT *ff, char *file) +int file_is_included(FF_PKT *ff, const char *file) { struct s_included_file *inc = ff->included_files_list; int len; for ( ; inc; inc=inc->next ) { if (inc->pattern) { - if (fnmatch(inc->fname, file, FNM_LEADING_DIR) == 0) { + if (fnmatch(inc->fname, file, fnmode|FNM_LEADING_DIR) == 0) { return 1; } continue; @@ -302,13 +322,13 @@ int file_is_included(FF_PKT *ff, char *file) * Determine if the file is excluded or not. */ static int -file_in_excluded_list(struct s_excluded_file *exc, char *file) +file_in_excluded_list(struct s_excluded_file *exc, const char *file) { if (exc == NULL) { Dmsg0(900, "exc is NULL\n"); } for ( ; exc; exc=exc->next ) { - if (fnmatch(exc->fname, file, FNM_PATHNAME) == 0) { + if (fnmatch(exc->fname, file, fnmode|FNM_PATHNAME) == 0) { Dmsg2(900, "Match exc pat=%s: file=%s:\n", exc->fname, file); return 1; } @@ -324,10 +344,14 @@ file_in_excluded_list(struct s_excluded_file *exc, char *file) * of an excluded directory. */ -int file_is_excluded(FF_PKT *ff, char *file) +int file_is_excluded(FF_PKT *ff, const char *file) { - char *p; + const char *p; + /* + * ***NB*** this removes the drive from the exclude + * rule. Why????? + */ if (win32_client && file[1] == ':') { file += 2; } @@ -341,7 +365,7 @@ int file_is_excluded(FF_PKT *ff, char *file) /* Match from the beginning of a component only */ if ((p == file || (*p != '/' && *(p-1) == '/')) && file_in_excluded_list(ff->excluded_files_list, p)) { - return 1; + return 1; } } return 0;