2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2015 Kern Sibbald
5 Copyright (C) 2009-2014 Free Software Foundation Europe e.V.
7 The original author of Bacula is Kern Sibbald, with contributions
8 from many others, a complete list can be found in the file AUTHORS.
10 You may use this file and others of this release according to the
11 license defined in the LICENSE file, which includes the Affero General
12 Public License, v3.0 ("AGPLv3") and some additional permissions and
13 terms pursuant to its AGPLv3 Section 7.
15 This notice must be preserved when any source code is
16 conveyed and/or propagated.
18 Bacula(R) is a registered trademark of Kern Sibbald.
22 * Program to test cache path
24 * Eric Bollengier, August 2009
30 #include "cats/cats.h"
31 #include "cats/bvfs.h"
32 #include "findlib/find.h"
36 static const char *file = "COPYRIGHT";
38 static const char *db_name = "regress";
39 static const char *db_user = "regress";
40 static const char *db_password = "";
41 static const char *db_host = NULL;
47 "\n%sVersion: %s (%s)\n"
48 " -d <nn> set debug level to <nn>\n"
49 " -dt print timestamp in debug output\n"
50 " -n <name> specify the database name (default bacula)\n"
51 " -u <user> specify database user name (default bacula)\n"
52 " -P <password specify database password (default none)\n"
53 " -h <host> specify database host (default NULL)\n"
54 " -w <working> specify working directory\n"
55 " -j <jobids> specify jobids\n"
56 " -p <path> specify path\n"
57 " -f <file> specify file\n"
58 " -l <limit> maximum tuple to fetch\n"
59 " -T truncate cache table before starting\n"
61 " -? print this message\n\n"), 2001, "", VERSION, BDATE);
65 static int result_handler(void *ctx, int fields, char **row)
67 Bvfs *vfs = (Bvfs *)ctx;
68 ATTR *attr = vfs->get_attr();
69 char empty[] = "A A A A A A A A A A A A A A";
71 memset(&attr->statp, 0, sizeof(struct stat));
72 decode_stat((row[BVFS_LStat] && row[BVFS_LStat][0])?row[BVFS_LStat]:empty,
73 &attr->statp, sizeof(attr->statp), &attr->LinkFI);
75 if (bvfs_is_dir(row) || bvfs_is_file(row)) {
76 /* display clean stuffs */
78 if (bvfs_is_dir(row)) {
79 pm_strcpy(attr->ofname, bvfs_basename_dir(row[BVFS_Name]));
81 /* if we see the requested file, note his filenameid */
82 if (bstrcmp(row[BVFS_Name], file)) {
83 fnid = str_to_int64(row[BVFS_FilenameId]);
85 pm_strcpy(attr->ofname, row[BVFS_Name]);
87 print_ls_output(vfs->get_jcr(), attr);
90 Pmsg5(0, "JobId=%s FileId=%s\tMd5=%s\tVolName=%s\tVolInChanger=%s\n",
91 row[BVFS_JobId], row[BVFS_FileId], row[BVFS_Md5], row[BVFS_VolName],
92 row[BVFS_VolInchanger]);
94 pm_strcpy(attr->ofname, file);
95 print_ls_output(vfs->get_jcr(), attr);
101 /* number of thread started */
103 int main (int argc, char *argv[])
106 char *jobids = (char *)"1";
107 char *path=NULL, *client=NULL;
110 setlocale(LC_ALL, "");
111 bindtextdomain("bacula", LOCALEDIR);
112 textdomain("bacula");
115 Dmsg0(0, "Starting bvfs_test tool\n");
117 my_name_is(argc, argv, "bvfs_test");
118 init_msg(NULL, NULL);
122 while ((ch = getopt(argc, argv, "h:c:l:d:n:P:Su:vf:w:?j:p:f:T")) != -1) {
124 case 'd': /* debug level */
125 if (*optarg == 't') {
126 dbg_timestamp = true;
128 debug_level = atoi(optarg);
129 if (debug_level <= 0) {
135 limit = str_to_int64(optarg);
151 working_directory = optarg;
159 db_password = optarg;
192 Pmsg0(0, _("Wrong number of arguments: \n"));
195 JCR *bjcr = new_jcr(sizeof(JCR), NULL);
196 bjcr->JobId = getpid();
197 bjcr->setJobType(JT_CONSOLE);
198 bjcr->setJobLevel(L_FULL);
199 bjcr->JobStatus = JS_Running;
200 bjcr->client_name = get_pool_memory(PM_FNAME);
201 pm_strcpy(bjcr->client_name, "Dummy.Client.Name");
202 bstrncpy(bjcr->Job, "bvfs_test", sizeof(bjcr->Job));
204 if ((db = db_init_database(NULL, NULL, db_name, db_user, db_password,
205 db_host, 0, NULL, false, false)) == NULL) {
206 Emsg0(M_ERROR_TERM, 0, _("Could not init Bacula database\n"));
208 Dmsg1(0, "db_type=%s\n", db_get_engine_name(db));
210 if (!db_open_database(NULL, db)) {
211 Emsg0(M_ERROR_TERM, 0, db_strerror(db));
213 Dmsg0(200, "Database opened\n");
215 Pmsg2(000, _("Using Database: %s, User: %s\n"), db_name, db_user);
221 Pmsg0(0, "Clean old table\n");
222 db_sql_query(db, "DELETE FROM PathHierarchy", NULL, NULL);
223 db_sql_query(db, "UPDATE Job SET HasCache=0", NULL, NULL);
224 db_sql_query(db, "DELETE FROM PathVisibility", NULL, NULL);
225 bvfs_update_cache(bjcr, db);
229 fs.set_handler(result_handler, &fs);
231 fs.set_jobids(jobids);
238 fs.ls_special_dirs();
240 while (fs.ls_files()) {
244 if (fnid && client) {
245 Pmsg0(0, "---------------------------------------------\n");
246 Pmsg1(0, "Getting file version for %s\n", file);
247 fs.get_all_file_versions(fs.get_pwd(), fnid, client);
254 Pmsg0(0, "list /\n");
256 fs.ls_special_dirs();
260 Pmsg0(0, "list /tmp/\n");
262 fs.ls_special_dirs();
266 Pmsg0(0, "list /tmp/regress/\n");
267 fs.ch_dir("/tmp/regress/");
268 fs.ls_special_dirs();
272 Pmsg0(0, "list /tmp/regress/build/\n");
273 fs.ch_dir("/tmp/regress/build/");
274 fs.ls_special_dirs();
278 fs.get_all_file_versions(1, 347, "zog4-fd");
281 strcpy(p, "/tmp/toto/rep/");
283 if(strcmp(p, "/tmp/toto/")) {
284 Pmsg0(000, "Error in bvfs_parent_dir\n");
287 if(strcmp(p, "/tmp/")) {
288 Pmsg0(000, "Error in bvfs_parent_dir\n");
292 Pmsg0(000, "Error in bvfs_parent_dir\n");
296 Pmsg0(000, "Error in bvfs_parent_dir\n");
300 Pmsg0(000, "Error in bvfs_parent_dir\n");