2 Bacula® - The Network Backup Solution
4 Copyright (C) 2009-2011 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from
7 many others, a complete list can be found in the file AUTHORS.
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version three of the GNU Affero General Public
10 License as published by the Free Software Foundation and included
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU Affero General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 Bacula® is a registered trademark of Kern Sibbald.
24 The licensor of Bacula is the Free Software Foundation Europe
25 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 Switzerland, email:ftf@fsfeurope.org.
30 * Program to test cache path
32 * Eric Bollengier, August 2009
38 #include "cats/cats.h"
39 #include "cats/sql_glue.h"
40 #include "cats/bvfs.h"
41 #include "findlib/find.h"
45 static const char *file = "COPYRIGHT";
47 static const char *db_name = "regress";
48 static const char *db_user = "regress";
49 static const char *db_password = "";
50 static const char *db_host = NULL;
56 "\nVersion: %s (%s)\n"
57 " -d <nn> set debug level to <nn>\n"
58 " -dt print timestamp in debug output\n"
59 " -n <name> specify the database name (default bacula)\n"
60 " -u <user> specify database user name (default bacula)\n"
61 " -P <password specify database password (default none)\n"
62 " -h <host> specify database host (default NULL)\n"
63 " -w <working> specify working directory\n"
64 " -j <jobids> specify jobids\n"
65 " -p <path> specify path\n"
66 " -f <file> specify file\n"
67 " -l <limit> maximum tuple to fetch\n"
68 " -T truncate cache table before starting\n"
70 " -? print this message\n\n"), 2001, VERSION, BDATE);
74 static int result_handler(void *ctx, int fields, char **row)
76 Bvfs *vfs = (Bvfs *)ctx;
77 ATTR *attr = vfs->get_attr();
78 char empty[] = "A A A A A A A A A A A A A A";
80 memset(&attr->statp, 0, sizeof(struct stat));
81 decode_stat((row[BVFS_LStat] && row[BVFS_LStat][0])?row[BVFS_LStat]:empty,
82 &attr->statp, sizeof(attr->statp), &attr->LinkFI);
84 if (bvfs_is_dir(row) || bvfs_is_file(row)) {
85 /* display clean stuffs */
87 if (bvfs_is_dir(row)) {
88 pm_strcpy(attr->ofname, bvfs_basename_dir(row[BVFS_Name]));
90 /* if we see the requested file, note his filenameid */
91 if (bstrcmp(row[BVFS_Name], file)) {
92 fnid = str_to_int64(row[BVFS_FilenameId]);
94 pm_strcpy(attr->ofname, row[BVFS_Name]);
96 print_ls_output(vfs->get_jcr(), attr);
99 Pmsg5(0, "JobId=%s FileId=%s\tMd5=%s\tVolName=%s\tVolInChanger=%s\n",
100 row[BVFS_JobId], row[BVFS_FileId], row[BVFS_Md5], row[BVFS_VolName],
101 row[BVFS_VolInchanger]);
103 pm_strcpy(attr->ofname, file);
104 print_ls_output(vfs->get_jcr(), attr);
110 /* number of thread started */
112 int main (int argc, char *argv[])
115 char *jobids = (char *)"1";
116 char *path=NULL, *client=NULL;
119 setlocale(LC_ALL, "");
120 bindtextdomain("bacula", LOCALEDIR);
121 textdomain("bacula");
124 Dmsg0(0, "Starting bvfs_test tool\n");
126 my_name_is(argc, argv, "bvfs_test");
127 init_msg(NULL, NULL);
131 while ((ch = getopt(argc, argv, "h:c:l:d:n:P:Su:vf:w:?j:p:f:T")) != -1) {
133 case 'd': /* debug level */
134 if (*optarg == 't') {
135 dbg_timestamp = true;
137 debug_level = atoi(optarg);
138 if (debug_level <= 0) {
144 limit = str_to_int64(optarg);
160 working_directory = optarg;
168 db_password = optarg;
201 Pmsg0(0, _("Wrong number of arguments: \n"));
204 JCR *bjcr = new_jcr(sizeof(JCR), NULL);
205 bjcr->JobId = getpid();
206 bjcr->setJobType(JT_CONSOLE);
207 bjcr->setJobLevel(L_FULL);
208 bjcr->JobStatus = JS_Running;
209 bjcr->client_name = get_pool_memory(PM_FNAME);
210 pm_strcpy(bjcr->client_name, "Dummy.Client.Name");
211 bstrncpy(bjcr->Job, "bvfs_test", sizeof(bjcr->Job));
213 if ((db = db_init_database(NULL, NULL, db_name, db_user, db_password,
214 db_host, 0, NULL, false, false)) == NULL) {
215 Emsg0(M_ERROR_TERM, 0, _("Could not init Bacula database\n"));
217 Dmsg1(0, "db_type=%s\n", db_get_type(db));
219 if (!db_open_database(NULL, db)) {
220 Emsg0(M_ERROR_TERM, 0, db_strerror(db));
222 Dmsg0(200, "Database opened\n");
224 Pmsg2(000, _("Using Database: %s, User: %s\n"), db_name, db_user);
230 Pmsg0(0, "Clean old table\n");
231 db_sql_query(db, "DELETE FROM PathHierarchy", NULL, NULL);
232 db_sql_query(db, "UPDATE Job SET HasCache=0", NULL, NULL);
233 db_sql_query(db, "DELETE FROM PathVisibility", NULL, NULL);
234 bvfs_update_cache(bjcr, db);
238 fs.set_handler(result_handler, &fs);
240 fs.set_jobids(jobids);
247 fs.ls_special_dirs();
249 while (fs.ls_files()) {
253 if (fnid && client) {
254 Pmsg0(0, "---------------------------------------------\n");
255 Pmsg1(0, "Getting file version for %s\n", file);
256 fs.get_all_file_versions(fs.get_pwd(), fnid, client);
263 Pmsg0(0, "list /\n");
265 fs.ls_special_dirs();
269 Pmsg0(0, "list /tmp/\n");
271 fs.ls_special_dirs();
275 Pmsg0(0, "list /tmp/regress/\n");
276 fs.ch_dir("/tmp/regress/");
277 fs.ls_special_dirs();
281 Pmsg0(0, "list /tmp/regress/build/\n");
282 fs.ch_dir("/tmp/regress/build/");
283 fs.ls_special_dirs();
287 fs.get_all_file_versions(1, 347, "zog4-fd");
290 strcpy(p, "/tmp/toto/rep/");
292 if(strcmp(p, "/tmp/toto/")) {
293 Pmsg0(000, "Error in bvfs_parent_dir\n");
296 if(strcmp(p, "/tmp/")) {
297 Pmsg0(000, "Error in bvfs_parent_dir\n");
301 Pmsg0(000, "Error in bvfs_parent_dir\n");
305 Pmsg0(000, "Error in bvfs_parent_dir\n");
309 Pmsg0(000, "Error in bvfs_parent_dir\n");