]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/tools/testfind.c
Change old get_Jobxxx to getJobxxx
[bacula/bacula] / bacula / src / tools / testfind.c
index 3b7876912fccd53f44070374ba1d648840386947..e3cd6c6d077d186776c38034835fb9a1426a06a6 100644 (file)
@@ -1,26 +1,41 @@
 /*
- * Test program for find files
- */
+   Bacula® - The Network Backup Solution
+
+   Copyright (C) 2000-2008 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 two of the GNU 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 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.
+*/
 /*
-   Copyright (C) 2000-2006 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.
-
+ * Test program for find files
+ *
+ *  Kern Sibbald, MM
+ *
  */
 
 #include "bacula.h"
 #include "dird/dird.h"
 #include "findlib/find.h"
 
-
 #if defined(HAVE_WIN32)
 #define isatty(fd) (fd==0)
 #endif
@@ -28,6 +43,8 @@
 /* Dummy functions */
 int generate_daemon_event(JCR *jcr, const char *event) { return 1; }
 int generate_job_event(JCR *jcr, const char *event) { return 1; }
+void generate_plugin_event(JCR *jcr, bEventType eventType, void *value) { }
+extern bool parse_dir_config(CONFIG *config, const char *configfile, int exit_code);
 
 /* Global variables */
 static int num_files = 0;
@@ -36,10 +53,11 @@ static int max_path_len = 0;
 static int trunc_fname = 0;
 static int trunc_path = 0;
 static int attrs = 0;
+static CONFIG *config;
 
 static JCR *jcr;
 
-static int print_file(FF_PKT *ff, void *pkt, bool);
+static int print_file(JCR *jcr, FF_PKT *ff, bool);
 static void count_files(FF_PKT *ff);
 static bool copy_fileset(FF_PKT *ff, JCR *jcr);
 static void set_options(findFOPTS *fo, const char *opts);
@@ -50,7 +68,8 @@ static void usage()
 "\n"
 "Usage: testfind [-d debug_level] [-] [pattern1 ...]\n"
 "       -a          print extended attributes (Win32 debug)\n"
-"       -dnn        set debug level to nn\n"
+"       -d <nn>     set debug level to <nn>\n"
+"       -dt         print timestamp in debug output\n"
 "       -c          specify config file containing FileSet resources\n"
 "       -f          specify which FileSet to use\n"
 "       -?          print this message.\n"
@@ -71,8 +90,8 @@ int
 main (int argc, char *const *argv)
 {
    FF_PKT *ff;
-   char *configfile = "bacula-dir.conf";
-   char *fileset_name = "Windows-Full-Set";
+   const char *configfile = "bacula-dir.conf";
+   const char *fileset_name = "Windows-Full-Set";
    int ch, hard_links;
 
    OSDependentInit();
@@ -80,6 +99,7 @@ main (int argc, char *const *argv)
    setlocale(LC_ALL, "");
    bindtextdomain("bacula", LOCALEDIR);
    textdomain("bacula");
+   lmgr_init_thread();
 
    while ((ch = getopt(argc, argv, "ac:d:f:?")) != -1) {
       switch (ch) {
@@ -92,10 +112,14 @@ main (int argc, char *const *argv)
             break;
 
          case 'd':                    /* set debug level */
+         if (*optarg == 't') {
+            dbg_timestamp = true;
+         } else {
             debug_level = atoi(optarg);
             if (debug_level <= 0) {
                debug_level = 1;
             }
+         }
             break;
 
          case 'f':                    /* exclude patterns */
@@ -112,7 +136,8 @@ main (int argc, char *const *argv)
    argc -= optind;
    argv += optind;
 
-   parse_config(configfile);
+   config = new_config_parser();
+   parse_dir_config(config, configfile, M_ERROR_TERM);
 
    MSGS *msg;
 
@@ -145,7 +170,12 @@ main (int argc, char *const *argv)
    find_files(jcr, ff, print_file, NULL);
 
    free_jcr(jcr);
-   free_config_resources();
+   if (config) {
+      config->free_resources();
+      free(config);
+      config = NULL;
+   }
+   
    term_last_jobs_list();
 
    /* Clean up fileset */
@@ -170,12 +200,6 @@ main (int argc, char *const *argv)
             fo->wildbase.destroy();
             fo->fstype.destroy();
             fo->drivetype.destroy();
-            if (fo->reader) {
-               free(fo->reader);
-            }
-            if (fo->writer) {
-               free(fo->writer);
-            }
          }
          incexe->opts_list.destroy();
          incexe->name_list.destroy();
@@ -219,11 +243,12 @@ main (int argc, char *const *argv)
    term_msg();
 
    close_memory_pool();
+   lmgr_cleanup_main();
    sm_dump(false);
    exit(0);
 }
 
-static int print_file(FF_PKT *ff, void *pkt, bool top_level) 
+static int print_file(JCR *jcr, FF_PKT *ff, bool top_level) 
 {
 
    switch (ff->type) {
@@ -338,11 +363,11 @@ static void count_files(FF_PKT *ar)
     * must be a path name (e.g. c:).
     */
    for (p=l=ar->fname; *p; p++) {
-      if (*p == '/') {
+      if (IsPathSeparator(*p)) {
          l = p;                       /* set pos of last slash */
       }
    }
-   if (*l == '/') {                   /* did we find a slash? */
+   if (IsPathSeparator(*l)) {                   /* did we find a slash? */
       l++;                            /* yes, point to filename */
    } else {                           /* no, whole thing must be path name */
       l = p;
@@ -429,7 +454,7 @@ static bool copy_fileset(FF_PKT *ff, JCR *jcr)
             fileset->incexe = (findINCEXE *)malloc(sizeof(findINCEXE));
             memset(fileset->incexe, 0, sizeof(findINCEXE));
             fileset->incexe->opts_list.init(1, true);
-            fileset->incexe->name_list.init(1, true);
+            fileset->incexe->name_list.init(0, 0);
             fileset->include_list.append(fileset->incexe);
          } else {
             ie = jcr_fileset->exclude_items[i];
@@ -438,7 +463,7 @@ static bool copy_fileset(FF_PKT *ff, JCR *jcr)
             fileset->incexe = (findINCEXE *)malloc(sizeof(findINCEXE));
             memset(fileset->incexe, 0, sizeof(findINCEXE));
             fileset->incexe->opts_list.init(1, true);
-            fileset->incexe->name_list.init(1, true);
+            fileset->incexe->name_list.init(0, 0);
             fileset->exclude_list.append(fileset->incexe);
          }
 
@@ -492,12 +517,6 @@ static bool copy_fileset(FF_PKT *ff, JCR *jcr)
             for (k=0; k<fo->drivetype.size(); k++) {
                current_opts->drivetype.append(bstrdup((const char *)fo->drivetype.get(k)));
             }
-            if (fo->reader) {
-               current_opts->reader = bstrdup(fo->reader);
-            }
-            if (fo->writer) {
-               current_opts->writer = bstrdup(fo->writer);
-            }
          }
 
          for (j=0; j<ie->name_list.size(); j++) {
@@ -615,6 +634,9 @@ static void set_options(findFOPTS *fo, const char *opts)
          fo->GZIP_level = *++p - '0';
          Dmsg1(200, "Compression level=%d\n", fo->GZIP_level);
          break;
+      case 'X':
+         fo->flags |= FO_XATTR;
+         break;
       default:
          Emsg1(M_ERROR, 0, _("Unknown include/exclude option: %c\n"), *p);
          break;