]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/tools/bvfs_test.c
Tweak fix MySQL quoting again :-(
[bacula/bacula] / bacula / src / tools / bvfs_test.c
index 0772873bfc195a727aeafa38244b760080fb73b5..af53d02c393f8ad89038105d833c2effb3480852 100644 (file)
@@ -1,21 +1,12 @@
-/*
- *
- *  Program to test cache path
- *
- *   Eric Bollengier, March 2007
- *
- *
- *   Version $Id$
- */
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2001-2006 Free Software Foundation Europe e.V.
+   Copyright (C) 2009-2009 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
+   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.
 
@@ -24,7 +15,7 @@
    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
+   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.
    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
    Switzerland, email:ftf@fsfeurope.org.
 */
+/*
+ *
+ *  Program to test cache path
+ *
+ *   Eric Bollengier, August 2009
+ *
+ *
+ */
 
 #include "bacula.h"
 #include "cats/cats.h"
@@ -42,7 +41,8 @@
  
 /* Local variables */
 static B_DB *db;
-
+static const char *file = "COPYRIGHT";
+static DBId_t fnid=0;
 static const char *db_name = "regress";
 static const char *db_user = "regress";
 static const char *db_password = "";
@@ -62,7 +62,8 @@ PROG_COPYRIGHT
 "       -w <working>      specify working directory\n"
 "       -j <jobids>       specify jobids\n"
 "       -p <path>         specify path\n"
-//"       -f <file>         specify file\n"
+"       -f <file>         specify file\n"
+"       -l <limit>        maximum tuple to fetch\n"
 "       -T                truncate cache table before starting\n"
 "       -v                verbose\n"
 "       -?                print this message\n\n"), 2001, VERSION, BDATE);
@@ -73,21 +74,34 @@ static int result_handler(void *ctx, int fields, char **row)
 {
    Bvfs *vfs = (Bvfs *)ctx;
    ATTR *attr = vfs->get_attr();
-   char *empty = "";
+   char empty[] = "A A A A A A A A A A A A A A";
+
+   memset(&attr->statp, 0, sizeof(struct stat));
+   decode_stat((row[BVFS_LStat] && row[BVFS_LStat][0])?row[BVFS_LStat]:empty,
+               &attr->statp, &attr->LinkFI);
 
-   if (fields == BVFS_DIR_RECORD || fields == BVFS_FILE_RECORD) {
-      decode_stat((row[BVFS_LStat])?row[BVFS_LStat]:empty,
-                  &attr->statp, &attr->LinkFI);
-      if (fields == BVFS_DIR_RECORD) {
+   if (bvfs_is_dir(row) || bvfs_is_file(row))
+   {
+      /* display clean stuffs */
+
+      if (bvfs_is_dir(row)) {
          pm_strcpy(attr->ofname, bvfs_basename_dir(row[BVFS_Name]));   
       } else {
+         /* if we see the requested file, note his filenameid */
+         if (bstrcmp(row[BVFS_Name], file)) {
+            fnid = str_to_int64(row[BVFS_FilenameId]);
+         }
          pm_strcpy(attr->ofname, row[BVFS_Name]);   
       }
       print_ls_output(vfs->get_jcr(), attr);
 
    } else {
-      Pmsg6(0, "%s\t%s\t%s\t%s\t%s\t%s",
-            row[0], row[1], row[2], row[3], row[4], row[5]);
+      Pmsg5(0, "JobId=%s FileId=%s\tMd5=%s\tVolName=%s\tVolInChanger=%s\n",
+            row[BVFS_JobId], row[BVFS_FileId], row[BVFS_Md5], row[BVFS_VolName],
+            row[BVFS_VolInchanger]);
+
+      pm_strcpy(attr->ofname, file);
+      print_ls_output(vfs->get_jcr(), attr);
    }
    return 0;
 }
@@ -98,7 +112,9 @@ static int result_handler(void *ctx, int fields, char **row)
 int main (int argc, char *argv[])
 {
    int ch;
-   char *jobids="1", *path=NULL, *file=NULL;
+   char *jobids = (char *)"1";
+   char *path=NULL, *client=NULL;
+   uint64_t limit=0;
    bool clean=false;
    setlocale(LC_ALL, "");
    bindtextdomain("bacula", LOCALEDIR);
@@ -112,7 +128,7 @@ int main (int argc, char *argv[])
 
    OSDependentInit();
 
-   while ((ch = getopt(argc, argv, "h:c:d:n:P:Su:vf:w:?j:p:f:T")) != -1) {
+   while ((ch = getopt(argc, argv, "h:c:l:d:n:P:Su:vf:w:?j:p:f:T")) != -1) {
       switch (ch) {
       case 'd':                    /* debug level */
          if (*optarg == 't') {
@@ -124,6 +140,13 @@ int main (int argc, char *argv[])
             }
          }
          break;
+      case 'l':
+         limit = str_to_int64(optarg);
+         break;
+
+      case 'c':
+         client = optarg;
+         break;
 
       case 'h':
          db_host = optarg;
@@ -154,7 +177,7 @@ int main (int argc, char *argv[])
          break;
 
       case 'f':
-         path = optarg;
+         file = optarg;
          break;
 
       case 'j':
@@ -204,10 +227,10 @@ int main (int argc, char *argv[])
    bjcr->db = db;
 
    if (clean) {
-      Pmsg0(0, "Clean old table");
-      db_sql_query(db, "DELETE FROM brestore_pathhierarchy", NULL, NULL);
-      db_sql_query(db, "DELETE FROM brestore_knownjobid", NULL, NULL);
-      db_sql_query(db, "DELETE FROM brestore_pathvisibility", NULL, NULL);
+      Pmsg0(0, "Clean old table\n");
+      db_sql_query(db, "DELETE FROM PathHierarchy", NULL, NULL);
+      db_sql_query(db, "UPDATE Job SET HasCache=0", NULL, NULL);
+      db_sql_query(db, "DELETE FROM PathVisibility", NULL, NULL);
       bvfs_update_cache(bjcr, db);
    }
 
@@ -216,12 +239,23 @@ int main (int argc, char *argv[])
 
    fs.set_jobids(jobids);
    fs.update_cache();
+   if (limit)
+      fs.set_limit(limit);
 
    if (path) {
       fs.ch_dir(path);
       fs.ls_special_dirs();
       fs.ls_dirs();
-      fs.ls_files();
+      while (fs.ls_files()) {
+         fs.next_offset();
+      }
+
+      if (fnid && client) {
+         Pmsg0(0, "---------------------------------------------\n");
+         Pmsg1(0, "Getting file version for %s\n", file);
+         fs.get_all_file_versions(fs.get_pwd(), fnid, client);
+      }
+
       exit (0);
    }